We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Array.prototype.del = function(){ console.log('aa'); } var a = new Array(); a.push(1); for(var k in a){ console.log(k); }
输出 0 del
导致数组遍历异常
The text was updated successfully, but these errors were encountered:
Sorry, something went wrong.
这是因为定义的del是可枚举的。可以换种方法定义del,而不用修改for in,
Object.defineProperty( Array.prototype,"del",{ set: function (e) {}, get: function () { return function(e) { e.sort(function (e, t) {return e - t;}); var t = this.concat([]); for (var n = e.length - 1; n >= 0; n--) t = t.slice(0, e[n]).concat(t.slice(e[n] + 1)); return t; } }, enumerable: false, configurable: false } );
关键是enumerable:false; 用这段代码,直接替换alloyimage.base.js或者alloyimage.js中开头的那个del的定义就可以避免后面使用for in出现问题。
No branches or pull requests
Array.prototype.del = function(){
console.log('aa');
}
var a = new Array();
a.push(1);
for(var k in a){
console.log(k);
}
输出
0
del
导致数组遍历异常
The text was updated successfully, but these errors were encountered: