我有.js文件链接到.htm文件,.js文件中唯一的代码是行:
Object.setPrototypeOf(Object.prototype,{x:616});
在加载.htm页面时,“chrome console”会显示错误:
Uncaught TypeError: Immutable prototype object '#<Object>' cannot have their prototype set
我以前从未见过这个错误,在这里或网上找不到任何东西。
我假设物体已被密封/冻结,因此运行测试:
console.warn('sealed ⇒',Object.isSealed(Object.prototype)); // false
console.warn('frozen ⇒',Object.isFrozen(Object.prototype)); // false
console.warn('extensible ⇒',Object.isExtensible(Object.prototype)); // true
但这没有解决问题,因此让我感到难过。这是第一次在设置Object.prototype
原型时发生这种情况,让我想知道我的Chrome浏览器是否已经自动更新了新功能?
这是ES7(又名ES2016)中的新功能。内置原型对象Object.prototype
现在是一个Immutable Prototype Exotic Objects,它的[[prototype]]
内部插槽被锁定。
它应该是prevent proxies from being inserted in the global lookup mechanism,请参阅this commit了解详情。它有recently been implemented in V8。