等待模块加载

时间:2013-02-15 10:13:47

标签: requirejs

我有以下代码:

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

0 个答案:

没有答案