未捕获的类型错误:不可变原型对象 '#<Object>'不能设置他们的原型 [英] Uncaught TypeError: Immutable prototype object &#39;#&lt;Object&gt;&#39; cannot have their prototype set

查看:103
本文介绍了未捕获的类型错误:不可变原型对象 '#<Object>'不能设置他们的原型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个链接到 .htm 文件的 .js 文件,而 .js 文件中唯一的代码是这一行:

I have a .js file linked to a .htm file and the only code within the .js file is the line:

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

加载 .htm 页面时,chrome 控制台"显示错误:

On loading the .htm page the "chrome console" displays the error:

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

但这并没有说明问题,因此让我难住了.这是有史以来第一次在设置 Object.prototype 的原型时发生这种情况,我是否想知道我的 Chrome 浏览器是否自动更新了新功能或其他内容?

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?

推荐答案

这是 ES7(又名 ES2016)中的新功能.内置原型对象 Object.prototype 现在是 Immutable Prototype Exotic Objects[[prototype]] 内部槽被锁定.

This is new in ES7 (aka ES2016). The builtin prototype object Object.prototype is now an Immutable Prototype Exotic Objects which has its [[prototype]] internal slot locked down.

应该是防止代理被插入全局查找机制,见此提交了解详情.它最近已在 V8 中实现.

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.

这篇关于未捕获的类型错误:不可变原型对象 '#<Object>'不能设置他们的原型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆