We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
要使用给定的原型创建对象,使用:
字面量语法:{ proto: ... },允许指定多个属性 或 Object.create(proto, [descriptors]),允许指定属性描述符。 Object.create 提供了一种简单的方式来浅拷贝对象及其所有属性描述符(descriptors)。
let clone = Object.create(Object.getPrototypeOf(obj), Object.getOwnPropertyDescriptors(obj)); 设置和访问原型的现代方法有:
[Object.getPrototypeOf(obj)]
(https://developer.mozilla.org/zh/docs/Web/JavaScript/Reference/Global_Objects/Object/getPrototypeOf) —— 返回对象 obj 的 [[Prototype]](与 proto 的 getter 相同)。
[Object.setPrototypeOf(obj, proto)]
(https://developer.mozilla.org/zh/docs/Web/JavaScript/Reference/Global_Objects/Object/setPrototypeOf) —— 将对象 obj 的 [[Prototype]] 设置为 proto(与 proto 的 setter 相同)。
不推荐使用内建的的 proto getter/setter 获取/设置原型,它现在在 ECMA 规范的附录 B 中。
我们还介绍了使用 Object.create(null) 或 {proto: null} 创建的无原型的对象。
这些对象被用作字典,以存储任意(可能是用户生成的)键。
通常,对象会从 Object.prototype 继承内建的方法和 proto getter/setter,会占用相应的键,且可能会导致副作用。原型为 null 时,对象才真正是空的。
The text was updated successfully, but these errors were encountered:
No branches or pull requests
要使用给定的原型创建对象,使用:
字面量语法:{ proto: ... },允许指定多个属性
或 Object.create(proto, [descriptors]),允许指定属性描述符。
Object.create 提供了一种简单的方式来浅拷贝对象及其所有属性描述符(descriptors)。
let clone = Object.create(Object.getPrototypeOf(obj), Object.getOwnPropertyDescriptors(obj));
设置和访问原型的现代方法有:
[Object.getPrototypeOf(obj)]
(https://developer.mozilla.org/zh/docs/Web/JavaScript/Reference/Global_Objects/Object/getPrototypeOf) —— 返回对象 obj 的 [[Prototype]](与 proto 的 getter 相同)。
[Object.setPrototypeOf(obj, proto)]
(https://developer.mozilla.org/zh/docs/Web/JavaScript/Reference/Global_Objects/Object/setPrototypeOf) —— 将对象 obj 的 [[Prototype]] 设置为 proto(与 proto 的 setter 相同)。
不推荐使用内建的的 proto getter/setter 获取/设置原型,它现在在 ECMA 规范的附录 B 中。
我们还介绍了使用 Object.create(null) 或 {proto: null} 创建的无原型的对象。
这些对象被用作字典,以存储任意(可能是用户生成的)键。
通常,对象会从 Object.prototype 继承内建的方法和 proto getter/setter,会占用相应的键,且可能会导致副作用。原型为 null 时,对象才真正是空的。
The text was updated successfully, but these errors were encountered: