var foo = (function() {
var proxy = {},
warning = false;
proxy.warn = function(msg) {
if (!warning) {
warning = true;
alert(msg);
}
return this; //For the purpose of method chaining we return proxy object.
}
function func() {
alert(warning); //This is a private function relative to foo.
}
return proxy;
}());
foo.warn(); //will alert
foo.warn(); //will not alert since warning has been set to true
警告の値を保持している新しいキーワードが使用されていないため、ここでインスタンス化について混乱していますか?警告が存在するスコープに関して、ここにリークはありますか?
ありがとうございました。