我會盡力在我的問題上儘可能清楚如此:JavaScript閉包上下文的其他屬性會發生什麼?
有很多博客和教程可以解釋閉包,但是我無法弄清楚的是上下文的其他屬性會發生什麼從哪個封閉創建? jsFiddle
function func(){
this.context_field = "context_field";
this.context_method = function(){
console.log("context method");
};
func = function(param, change){
if(typeof(change) === 'undefined'){
//......
console.log(param + " " + context_field + " from original func - closure\n\n");
//.....
}
return func;
};
func()("Init finished and call");
func("Call again", "");
您是否明白'this'是'window'(假設非嚴格模式)? – apsillers 2013-04-25 19:15:10