[[Set]] 对象的属性
[[Set]] attribute of the object
在阅读 Principles of Object-Oriented JavaScript
时,我在作者网站上的免费章节 page 32 末尾看到了以下行:
When a property is first added to an object, JavaScript uses an
internal method called [[Put]] on the object. The [[Put]] method
creates a spot in the object to store the property.
When a new value is assigned to an existing property, a separate
operation called [[Set]] takes place. This operation replaces the
current value of the property with the new one.
作者在这里讨论了 命名数据 属性 的更改值,这是由于名为 [[Set]] 的对象的内部属性而发生的。
我查看了 ECMA 5 并找到了 [[Get]] 和 [[Put]] 但没有这样的属性 [[Set]]。但是 [[Set]] 属性可用于对象中的命名访问器。
我的问题是有什么对象内部属性叫 [[Set]] 吗?如果不是,那么如何更改数据 属性 的值?
那是因为 [[Put]] 在 ECMAScript 6 中被重命名为 [[Set]]。
具体来说,来自 Early ES6 Working Drafts、
修订版 12(2012 年 11 月 22 日草案)
Replaced [[Get]]/[[Put]] with [[GetP]]/[[SetP]].
修订版 14(2013 年 3 月 8 日草案)
Rename [[GetP]] to [[Get]] and [[SetP]] to [[Set]]
在 ES5 中有一个 [[Put]] 内部方法,没有 [[Set]]。在 ES6 中有一个 [[Set]] 内部方法而没有 [[Put]]。或多或少,他们的行为是一样的。
在阅读 Principles of Object-Oriented JavaScript
时,我在作者网站上的免费章节 page 32 末尾看到了以下行:
When a property is first added to an object, JavaScript uses an internal method called [[Put]] on the object. The [[Put]] method creates a spot in the object to store the property.
When a new value is assigned to an existing property, a separate operation called [[Set]] takes place. This operation replaces the current value of the property with the new one.
作者在这里讨论了 命名数据 属性 的更改值,这是由于名为 [[Set]] 的对象的内部属性而发生的。 我查看了 ECMA 5 并找到了 [[Get]] 和 [[Put]] 但没有这样的属性 [[Set]]。但是 [[Set]] 属性可用于对象中的命名访问器。
我的问题是有什么对象内部属性叫 [[Set]] 吗?如果不是,那么如何更改数据 属性 的值?
那是因为 [[Put]] 在 ECMAScript 6 中被重命名为 [[Set]]。
具体来说,来自 Early ES6 Working Drafts、
修订版 12(2012 年 11 月 22 日草案)
Replaced [[Get]]/[[Put]] with [[GetP]]/[[SetP]].
修订版 14(2013 年 3 月 8 日草案)
Rename [[GetP]] to [[Get]] and [[SetP]] to [[Set]]
在 ES5 中有一个 [[Put]] 内部方法,没有 [[Set]]。在 ES6 中有一个 [[Set]] 内部方法而没有 [[Put]]。或多或少,他们的行为是一样的。