__proto__ 和 Object.getPrototype 是否公开了完全相同的功能? [英] Do __proto__ and Object.getPrototype of expose exactly the same functionality?

查看:18
本文介绍了__proto__ 和 Object.getPrototype 是否公开了完全相同的功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ES2015 对__proto__ 的标准化是否否定了对Object.getPrototypeOf 的需求?

Does the standardization of __proto__ in ES2015 negate the need for Object.getPrototypeOf?

推荐答案

__proto__Object.getPrototype 是否公开了完全相同的功能?

Do __proto__ and Object.getPrototype of expose exactly the same functionality?

没有..__proto__ 仅适用于从 Object.prototype 继承的对象.并且 Object.getPrototype 不允许改变原型.

No. .__proto__ only works on objects that inherit from Object.prototype. And Object.getPrototype doesn't allow to mutate the prototype.

ES2015 对__proto__ 的标准化是否否定了对Object.getPrototypeOf 的需求?

Does the standardization of __proto__ in ES2015 negate the need for Object.getPrototypeOf?

你已经倒退了.ES5 Object.getPrototypeOf 和 ES6 Object.setPrototypeOf 完全不需要使用 __proto__.

You've got it backwards. ES5 Object.getPrototypeOf and ES6 Object.setPrototypeOf completely negate the need to ever use __proto__.

Object.prototype.__proto__ 访问器属性仅在 ES6 中标准化,以实现需要它的实现之间的向后兼容性和互操作性.它被明确标记为 Web 遗留功能.检查附录 B 上的注释(...遗留特性 [用于] 基于 Web 浏览器的 ECMAScript 实现.[它们] 具有 [...] 不受欢迎的特性,并且 [...] 将从本规范中删除 [如果不使用] 大量现有网页 [...]. 程序员在编写新的 ECMAScript 代码时不应使用或假设 [它们] 的存在.不鼓励 ECMAScript 实现实现这些功能.")

The Object.prototype.__proto__ accessor property is only standardised in ES6 for backwards compatibility and interoperability between implementations that need it. It's explictly marked as a web legacy feature. Check the note on Annex B ("…legacy features [for] web browser based ECMAScript implementations. [They] have […] undesirable characteristics and […] would be removed from this specification [if not used] by large numbers of existing web pages […]. Programmers should not use or assume the existence of [them] when writing new ECMAScript code. ECMAScript implementations are discouraged from implementing these features.")

这篇关于__proto__ 和 Object.getPrototype 是否公开了完全相同的功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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