TypeError: 属性 Array.prototype.splice.call(..) 是不可配置的,无法删除
TypeError: property Array.prototype.splice.call(...) is non-configurable and can't be deleted
当我尝试在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.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); // []
从querySelectorAll()
返回的NodeList
具有不可配置的属性,splice
无法按预期进行更改。
相关文章:
- 使用php或javascript从facebook相册URL中删除多余的部分
- RegEx删除空属性?例如,如果(class=“”||class=“”)移除;否则就下课
- 如何删除多行HTML排列中的空白
- 如何从rails中的代码中删除新行( )
- 删除对HTML元素的拖动
- 当图像转换为本地存储的DataURL时,EXIF被删除
- 按顺序添加和删除类
- iframe正在添加标签,需要删除它们
- RequireJS向模块传递配置总是返回undefined
- 如何在HTML输入字段中添加不可删除的后缀
- addData()从最新图表中删除.js 2.1.3-怎么了
- 为什么此可配置属性不可删除
- 正在删除配置文件请求
- TypeError: 属性 Array.prototype.splice.call(..) 是不可配置的,无法删除
- 如何删除配置文件中的状态栏
- 删除 RequireJS 中未使用的填充程序配置
- 类型错误:属性 1 不可配置,无法删除
- 删除或覆盖Restangular中限定范围配置的请求拦截器
- 如果我允许用户为他们的“配置文件”编写HTML,我应该禁止/删除哪些元素以保证其他用户的安全
- jsTree 3.3.2 -如何配置jsTree,以便只有一些节点是可拖动的,并且可以在某个级别上删除