亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

javascript 閉包疑問

 更新時間:2010年12月30日 19:37:30   作者:  
今天在編碼時,遇到一個問題,特記錄下。希望對朋友有所幫助。
復(fù)制代碼 代碼如下:

var test=(function() { var arr2=[1,2,3,3]; return function(){ return arr2; }; })()
Array.prototype.f1= function () { return []; }
Array.prototype.f2= function () { this.length=0; return this; }   

然后用兩種方式調(diào)用:
一:var arr= test();
console.log(arr.length);結(jié)果是4
arr.f1();
arr= test();
console.log(arr.length);結(jié)果是4
這個好理解;

二:var arr= test();
console.log(arr.length);結(jié)果是4
arr.f2();
arr= test();
console.log(arr.length);結(jié)果是0
不知道為什么會這樣,難道arr.f2()可以修改test函數(shù)中閉包中的arr2;

相關(guān)文章

最新評論