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; }
Then call it in two ways:
One: var arr= test();
console. log(arr.length); the result is 4
arr.f1();
arr= test();
console.log(arr.length); the result is 4
This is easy to understand;
Two: var arr= test();
console.log(arr.length); the result is 4
arr.f2();
arr= test();
console.log(arr.length); the result is 0
I don’t know why this is happening. Could it be that arr.f2() can modify arr2 in the closure in the test function?