【发布时间】:2012-04-17 14:57:39
【问题描述】:
假设我有这个模块,我希望它自行初始化并附加到它的作用域。像这样:
(function( scope ) {
var Module = (function() {
return {
init: function(){
console.log('Initialized');
}
};
})();
var module = scope.Module = Module;
module.init();
})( self );
现在的问题是,self 始终是 window。我不想要那个。我希望它成为 jQuery 的$.getScript() 调用和加载它的范围,如下所示:
var Master = (function($) {
return {
init: function() {
var self = this;
$.getScript("/js/libs/module.js");
}
}
})(jQuery)
有办法破解吗?
【问题讨论】:
标签: javascript jquery scope module-pattern revealing-module-pattern