各インスタンスに固有のコンテキストを使用して、モジュールをページに複数回ロードしたいと考えています。これを行う通常の方法は 2 つあります。
- モジュールはコンストラクターを返すことができます
- コンテキスト ID を指定して、require メソッドを明示的に実行できます。
私の状況ではこれらのどちらでも機能しますが、3 番目のオプションが必要です。:)
新しいコンテキストでモジュールを返す requirejs プラグインが必要です。つまり、
require(["new!some/module"], function(SomeModule) {
// SomeModule, here, is in its own context. If i were to run this
// method call again, SomeModule would be in a new context.
});
これを行うためのプラグインの構築を検討し始めました...
load: function (name, req, load, config) {
var index = get_unique_index();
req({context:index}, [name], function(value) {
if(!config.isBuild){
load(value);
}
});
}
しかし、{context:index} dict はここでは機能しません...