0
我得到這個代碼塊:閉合控制流程
(function($, exports) {
var mod = function(includes) {
if (includes) this.include(includes);
};
mod.fn = mod.prototype;
mod.fn.proxy = function(func) {
return $.proxy(func, this);
};
mod.fn.load = function(func) {
$(this.proxy(func));
};
mod.fn.include = function(ob) {
$.extend(this, ob);
};
exports.Controller = mod;
})(jQuery, window);
(function($, Controller) {
mod = new Controller;
mod.toggleClass = function(e) {
this.view.toggleClass("over", e.data);
};
mod.load(function() {
this.test = 'test';
console.log(this.test); // Delayed
this.view = $("#view");
});
console.log(mod.view) // returns undefined
console.log(mod);
})(jQuery, Controller);
在Firefox上執行時,螢火控制檯面板上的結果如下:
undefined
Object { toggleClass=function(), proxy=function(), load=function(), more...}
test
這意味着最後兩個日誌功能(它們放置在代碼塊的底部)在第一個之前被執行(它是:console.log(this.test); //延遲)
你能解釋爲什麼這樣的流發生了嗎?