/ /ネストされたIIFEモジュールで親JavaScript関数を参照するにはどうすればよいですか? [複製]-javascript、jquery、iife

ネストされたIIFEモジュールで親のJavaScript関数を参照する方法[重複] - javascript、jquery、iife

以下のコードを見てください... setTimeout 匿名関数、参照する正しい方法は何ですか alert.hide() 方法?呼び出し全体を次のように書くだけで正しいですか admin.alert.hide();?または参照するより良い方法はありますか admin 直接呼び出す必要はありませんか?

var admin = (function(jQuery, window, document, undefined) {
return {
loader : (function(admin) {
var fade = 75;
var loader = "#loader";
return {
show : function () {
jQuery(loader).stop().fadeIn(fade);
},
hide : function() {
jQuery(loader).stop().fadeOut(fade);
}
}
})(),
alert : (function() {
var timeout;
var fade = 500;
var milliseconds = 1000;
var alert = "#alert";
return {
timeout : timeout,
show : function(message) {
jQuery(alert).find("p").text(message);
jQuery(alert).stop().fadeIn(fade);
clearTimeout(this.timeout);
this.timeout = setTimeout(function() {  }, milliseconds);
},
hide : function() {
jQuery(alert).stop().fadeOut(fade);
}
}
})()
}
})(jQuery, window, document);

回答:

回答№1の場合は3

あなたは以下を行うことができます:

return
{
timeout : timeout,
show : function(message)
{
jQuery(alert).find("p").text(message);
jQuery(alert).stop().fadeIn(fade);
clearTimeout(this.timeout);
this.timeout = setTimeout((function() { this.hide(); }).bind(this), milliseconds);
},
hide : function()
{
jQuery(alert).stop().fadeOut(fade);
}
}