2016-11-18 67 views
0

我使用了很多类似的类,它们都使用相同的依赖关系,因此它们都以相同的ES2015导入语句列表开始。我想知道的是,使用继承或什么的,我可以这样做,这只是在父母需要防止冗余代码?请注意,我为每个文件使用1个类。在JavaScript ES2015扩展类中,我必须重新导入所有依赖项吗?

import angular from 'angular; 
import {subscribeReducer} from '../shared/helpers/reduce.helper'; 
import newhomeReducer from './newhome.reducer'; 

import {subscribeSaga} from '../shared/helpers/saga.helper'; 
import newhomeSagas from './newhome.saga'; 

class Newhome{...something...}; 

,然后第2类:

import angular from 'angular; 
import {subscribeReducer} from '../shared/helpers/reduce.helper'; 
import currenthomeReducer from './newhome.reducer'; 

import {subscribeSaga} from '../shared/helpers/saga.helper'; 
import currenthomeSagas from './newhome.saga'; 

class Currenthome{...something...}; 
+1

你只需要导入你引用的内容,所以如果你没有引用某个东西,那么你就不需要导入了。另外一个好的编辑器会让你知道你没有引用什么,例如。我使用Atom.IO,eslint,如果我添加一个未被引用的导入,它会让我知道。 – Keith

回答

1

不,你不必重新导入您的依赖关系,除非你在子类中使用它们。

例如,如果你的子类才:

class Currenthome extends Newhome {} 

,那么你不必重新输入您的依赖;但是如果你在子类中使用它们:

class Currenthome extends Newhome { 
    someMethod() { 
    angular.doSomething(); 
    } 
} 

那么你必须导入它们。

相关问题