2015-01-08 113 views
0

我试图只加载event_broker module in the chaplinjs
我能够通过执行类似同步加载一个chaplin模块

require(["underscore", "chaplin"], function(_, chaplin) 
{ 
var eventBroker = _({}).extend(chaplin.EventBroker); 
}); 

但要做到,这是不是在我的情况不够好。我需要能够同步加载event_broker模块。我知道那是需要设计的。有没有办法做到这一点?

回答

1

我知道那是需要设计的。

不,那是不是 RequireJS的设计目的是什么。 (你忘了把“不”放在那里?)RequireJS被设计为异步加载模块

我通常会建议通过script元素加载卓别林,因为这会是同步的,但是在查看卓别林的代码后,我发现如果它没有检测到CommonJS或AMD环境,则会失败,并返回throw new Error('Chaplin requires Common.js or AMD modules');

Almond可以用来同步加载AMD模块的捆绑包,所以这可能是您的选择。