Javascript TypeError:property Array.prototype.splice.call(…)是不可配置的,可以';不能删除
当我尝试在FF中加载我的页面时,出现以下错误:Javascript TypeError:property Array.prototype.splice.call(…)是不可配置的,可以';不能删除,javascript,prototypejs,Javascript,Prototypejs,当我尝试在FF中加载我的页面时,出现以下错误: TypeError: property Array.prototype.splice.call(...) is non-configurable and can't be deleted 这是原型 HTMLElement.prototype.selectorAll = function (selectors, fun) { var sels = Array.prototype.splice.call(this.queryS
TypeError: property Array.prototype.splice.call(...) is non-configurable and can't be deleted
这是原型
HTMLElement.prototype.selectorAll = function (selectors, fun) {
var sels = Array.prototype.splice.call(this.querySelectorAll(selectors), 0)
if (!fun) { return sels; }; fun.call(sels);
};
如何修复此错误?使用而不是仅从原始集合创建新的数组
var sels = Array.prototype.slice.call(this.querySelectorAll(selectors), 0)
该错误是因为splice
还试图修改原始集合:
var a = [ 1, 2, 3, 4 ];
a.slice(0);
console.log(a); // [ 1, 2, 3, 4 ]
a.splice(0);
console.log(a); // []
从querySelectorAll()
返回的NodeList
有一个不可配置的属性,splice
无法按预期更改。谢谢!修好了!