同步加载chaplin模块

时间:2015-01-08 05:11:38

标签: requirejs chaplinjs

我正在尝试加载 event_broker module in the chaplinjs
我可以做类似

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

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

1 个答案:

答案 0 :(得分:1)

  

我知道这是需要做的事情。

不,那是 RequireJS的目的。 (你忘了把#34;不是"在那里?)RequireJS旨在异步加载模块

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

Almond可用于同步加载AMD模块的捆绑,因此可能可供您选择。

相关问题