/ / नेस्टेड आईआईएफई मॉड्यूल में पेरेंट जावास्क्रिप्ट फ़ंक्शन का संदर्भ कैसे लें? [डुप्लिकेट] - जावास्क्रिप्ट, jquery, iife

एक नेस्टेड आईआईएफई मॉड्यूल में एक मूल जावास्क्रिप्ट फ़ंक्शन का संदर्भ कैसे लें? [डुप्लिकेट] - जावास्क्रिप्ट, 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);

उत्तर:

जवाब के लिए 3 № 1

आप निम्नलिखित कर सकते हैं:

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);
}
}