【发布时间】:2014-06-08 14:42:00
【问题描述】:
在下面的 CommonJS/Browserify 模块中,我怎样才能避免每次都导入 foo 和 bar —— 而是只导入基于 init() 中的条件所需的那个?
var Foo = require('foo'),
Bar = require('bar'),
Component = function(config) {
this.type = config.type;
this.init();
};
Component.prototype = {
init: function() {
var instance = null;
switch (this.type) {
case ('foo'):
instance = new Foo(...);
break;
case ('bar'):
instance = new Bar(...);
break;
}
}
};
【问题讨论】:
标签: javascript node.js commonjs browserify