我有以下代码:
define([],
function() {
var AppSettings = function(){};
AppSettings.prototype = {
init: function() {
var that = this;
//...
require(views,function(){
var counter = 0;
for(view in that.settings.initViews) {
that.initViews[view] = new arguments[counter++];
}
console.log("init");
});
},
run: function() {
console.log("run");
}
};
return AppSettings;
}
);
当我加载 AppSettings 模块时:
require(["app_settings"],
function(AppSettings) {
var settings = new AppSettings();
settings.init();
setting.run();
}
);
我得到以下输出:
run
init
这可能是因为我在 init 方法中异步加载模块 - 但我如何“等待”它们加载?我的意思是我如何确保所有异步都完成然后调用run
?