当我尝试在 FF 中加载我的页面时,出现此错误:
TypeError: property Array.prototype.splice.call(...) is non-configurable and can't be deleted
这是原型(prototype)
HTMLElement.prototype.selectorAll = function (selectors, fun) {
var sels = Array.prototype.splice.call(this.querySelectorAll(selectors), 0)
if (!fun) { return sels; }; fun.call(sels);
};
如何修复此错误?
最佳答案
使用 slice
而不是 splice
只是创建一个新的 Array
来自原始集合。
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); // []
还有 NodeList
从 querySelectorAll()
返回有一个不可配置的属性 splice
不能像预期的那样改变。
关于javascript - TypeError : property Array. prototype.splice.call(...) 不可配置,无法删除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19746781/