2015-01-08 56 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模塊的捆綁包,所以這可能是您的選擇。