简体   繁体   English

未捕获的TypeError:不可变原型对象'#<Object>'不能设置原型

[英]Uncaught TypeError: Immutable prototype object '#<Object>' cannot have their prototype set

I have a .js file linked to a .htm file and the only code within the .js file is the line: 我有.js文件链接到.htm文件,.js文件中唯一的代码是行:

Object.setPrototypeOf(Object.prototype,{x:616});

On loading the .htm page the "chrome console" displays the error: 在加载.htm页面时,“chrome console”会显示错误:

Uncaught TypeError: Immutable prototype object '#<Object>' cannot have their prototype set

I've never seen this error before and can't find anything for it here or online. 我以前从未见过这个错误,在这里或网上找不到任何东西。

I assumed that the object had been sealed/frozen, so ran the tests: 我假设物体已被密封/冷冻,因此进行了测试:

console.warn('sealed        ⇒',Object.isSealed(Object.prototype));      //  false
console.warn('frozen        ⇒',Object.isFrozen(Object.prototype));      //  false
console.warn('extensible    ⇒',Object.isExtensible(Object.prototype));  //  true

But this shed no light on the problem and as such has left me stumped. 但这没有解决问题,因此让我感到难过。 This is the first ever time that this has happened when setting the prototype of Object.prototype and has me wondering if my Chrome browser has auto-updated with new features or something? 这是设置Object.prototype原型时第一次发生这种情况,让我想知道我的Chrome浏览器是否已经自动更新了新功能?

This is new in ES7 (aka ES2016). 这是ES7(又名ES2016)中的新功能。 The builtin prototype object Object.prototype is now an Immutable Prototype Exotic Objects which has its [[prototype]] internal slot locked down. 内置原型对象Object.prototype现在是一个不可变的原型Exotic Objects ,它的[[prototype]]内部插槽被锁定。

It is supposed to prevent proxies from being inserted in the global lookup mechanism , see this commit for details. 它应该阻止代理插入全局查找机制 ,有关详细信息,请参阅此提交 It has recently been implemented in V8 . 最近已在V8中实施

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM