f.e.我有:requirejs再次執行require模塊
require(['module1'], function(module1_callback){
//callback_1 after code is loaded
});
和module1.js
define(['module2'], function(module2_callback)
{
//function_1 to perform something
return 'something';
});
我需要點播模塊1,但我需要運行function_1每次我requre該模塊, 在模塊1這種情況下function_1僅在第一次執行負載,但我需要每次我需要module1的例程。只返回回調執行
這是否意味着,每一個未定義的模塊需要重新加載以及如何與編譯的模塊這項工作? –
上下文將不會被再次加載,它將從緩存中取出,但只有文件上下文,如果你的模塊返回編譯的東西,它將被重新編譯,basiccaly它會在該模塊上再次執行eval –
你的方法看起來有點過於複雜。僅僅爲模塊本身添加一個復位功能不是更容易。或者甚至更好的在你的模塊中有一個getter,爲你提供一個新的實例。 –