0
此代碼是直接從複製的情況下:更改自動執行功能
// Set the singleton value to the return value of the self-
// executing function block.
var singleton = (function(){
// Declare a private variable.
var message = "Stop playing with your context!";
this.getMessage = function(){
return(message);
};
// Return this object reference.
return(this);
}).call({});
// alert the singleton message.
alert("Message:", singleton.getMessage());
我的想法是,我可以用它來更好地包含在我的程序的變量和函數。
然而,當我嘗試運行在的jsfiddle代碼:
它不會返回消息。我錯過了什麼?
哇好,我覺得我應該重視這個問題了,把一個問題了那裏我實際上有實現這是一個問題......總之,謝謝你 – TaylorMac
護理標記答案被接受? :-) –