【发布时间】:2012-04-11 00:50:02
【问题描述】:
也许我在某个地方的文档中错过了这一点,但这里是这样。我有一个负责管理模块的核心控制器。到目前为止,我有大约 20 个模块,并且希望能够轻松地将它们配置为由核心加载。这意味着我有一个大数组或很多调用需要。在文字对象中创建模块列表然后让模块加载它的依赖项是否可以接受/良好做法?这是我的意思的一个例子:
Config.js
modules = [
'moduleA',
'moduleB',
'moduleC'
];
Core.JS
define(
['config'],
function(config) {
// Somewhere in here I parse the list and require() each one ?
return {
startAll : function() {
console.log('starting all modules.');
// Then call a method common to all 'modules' in the list above.
}
}
};
}
);
我不确定这是否是一个好主意,因为我是 RequireJS 的新手,但我喜欢能够配置从一个地方加载哪些模块的想法。在我的模块中,我指的是我更具体地编写的 UI 小部件。
【问题讨论】:
标签: javascript dependencies requirejs