接上一篇,是第六部分中关于对象类型的标准阐述。
6.1.7 The Object Type
原文:An Object is logically a collection of properties. Each property is either a data property, or an accessor property:
- A data property associates a key value with an ECMAScript language value and a set of Boolean attributes.
- An accessor property associates a key value with one or two accessor functions, and a set of Boolean attributes. The accessor functions are used to store or retrieve an ECMAScript language value that is associated with the property.
译文:对象是一组具有逻辑关系的属性的集合。每个属性都是一个数据属性(write)或者是一个访问器属性(set/get):
- 数据属性由一个ECMAScript的语言值和一组布尔特性组成的键值;
- 访问器属性是由一个或两个访问器函数(get/set)和一组布尔值特性构成的键值。访问器函数具有读写一个与属性相关联的ECMAScript语言值的功能。
原文:Properties are identified using key values. A property key value is either an ECMAScript String value or a Symbol value. All String and Symbol values, including the empty string, are valid as property keys. A property name is a property key that is a String value.
An integer index is a String-valued property key that is a canonical numeric String (see 7.1.16) and whose numeric value is either +0 or a positive integer ≤ 253-1. An array index is an integer index whose numeric value i is in the range +0 ≤ i < 232-1.
译文:属性明确了要采用键值对的形式来表现。一个属性的键可以是一个ECMAScript的字符串类型或Symbol类型的值。所有的字符串或Symbol值,包括空字符串,都是有效的属性键。一个属性的名称就是这个属性键的字符串值。
(此段翻译拿不准,希望高手能指点)一个整数索引,是数值为+0或者小于等于2^53-1的一个正整数数值的字符串型的属性键。数组索引是一个在大于等于+0小于2^32-1之间的范围间的整数索引值。
原文:Property keys are used to access properties and their values. There are two kinds of access for properties: get and set, corresponding to value retrieval and assignment, respectively. The properties accessible via get and set access includes both own properties that are a direct part of an object and inherited properties which are provided by another associated object via a property inheritance relationship. Inherited properties may be either own or inherited properties of the associated object. Each own property of an object must each have a key value that is distinct from the key values of the other own properties of that object.
译文:属性的键用来操作属性和它所关联的值。有两种操作的方式:get和set,分别对应着读取值和写入值。属性可以通过get和set操作包括由对象直接定义的自有属性和由其他关联对象通过继承关系得来的继承属性。继承属性则可能是该关联对象自己直接定义的或者是由它继承来的其他属性。同一个对象的每一个自有属性其键名必须是唯一的。
原文:All objects are logically collections of properties, but there are multiple forms of objects that differ in their semantics for accessing and manipulating their properties. Ordinary objects are the most common form of objects and have the default object semantics. An exotic object is any form of object whose property semantics differ in any way from the default semantics.
译文:所有的对象都是有逻辑关系的属性的集合,但是由于访问和操作属性的不同语义解释又会有多种形式的对象。普通对象是一种具有默认对象语义解释的最常用的形式。特殊对象是具有与默认语义解释完全不同的属性的一种特殊对象表现形式。
6.1.7.3 Invariants of the Essential Internal Methods 内部方法
原文:[[GetPrototypeOf]] ( )
- The Type of the return value must be either Object or Null.
- If target is non-extensible, and [[GetPrototypeOf]] returns a value v, then any future calls to [[GetPrototypeOf]] should return the SameValue as v.
NOTE 1 An object's prototype chain should have finite length (that is, starting from any object, recursively applying the [[GetPrototypeOf]] internal method to its result should eventually lead to the value null). However, this requirement is not enforceable as an object level invariant if the prototype chain includes any exotic objects that do not use the ordinary object definition of [[GetPrototypeOf]]. Such a circular prototype chain may result in infinite loops when accessing object properties.
译文:[[GetPrototypeOf]] ( )
- 方法的返回值类型必须是Object或Null;
- 如果目标对象是不可扩展的,且该方法返回一个值v,那么任何未来针对该方法的调用,都应该返回同一个值v。
注释1:对象的原形链应该是有限长度的(即从任何对象开始,递归调用[[GetPrototypeOf]] ( )方法,最终应该得到一个null值为结束)。但是,如果一个对象原型链包括任何特殊对象(即不使用常规定义[[GetPrototypeOf]] 内部方法)时,这就不是一个强制的必要条件,比如一个环状的原形链就可能导致无限循环调用属性。
原文:[[SetPrototypeOf]] (V)
- The Type of the return value must be Boolean.
- If target is non-extensible, [[SetPrototypeOf]] must return false, unless V is the SameValue as the target's observed [[GetPrototypeOf]] value.
译文:[[SetPrototypeOf]] (V)
- 该方法的返回值必须是Boolean类型
- 如果目标对象是不可扩展的,该方法必须返回false,除非传入的参数V与该目标相关属性通过[[GetPrototypeOf]]的到的值为相同的值。
原文:[[IsExtensible]] ( )
- The Type of the return value must be Boolean.
- If [[IsExtensible]] returns false, all future calls to [[IsExtensible]] on the target must return false.
译文:[[IsExtensible]] ( )
- 该方法返回值必须是Boolean类型;
- 如果该方法返回false, 则目标对象未来针对该方法的所有调用,都必须返回false。
原文:[[PreventExtensions]] ( )
- The Type of the return value must be Boolean.
- If [[PreventExtensions]] returns true, all future calls to [[IsExtensible]] on the target must return false and the target is now considered non-extensible.
译文:[[PreventExtensions]] ( )
- 该方法的返回值必须是Boolean类型;
- 如果该方法返回true,则目标对象从此刻将被认为是不可扩展的,并且该对象未来所有针对[[IsExtensible]]方法的调用都必须返回false。
原文:[[GetOwnProperty]] (P)
- The Type of the return value must be either Property Descriptor or Undefined.
- If the Type of the return value is Property Descriptor, the return value must be a complete property descriptor (see 6.2.5.6).
- If a property P is described as a data property with Desc.[[Value]] equal to v and Desc.[[Writable]] and Desc.[[Configurable]] are both false, then the SameValue must be returned for the Desc.[[Value]] attribute of the property on all future calls to [[GetOwnProperty]] ( P ).
- If P's attributes other than [[Writable]] may change over time or if the property might disappear, then P's [[Configurable]] attribute must be true.
- If the [[Writable]] attribute may change from false to true, then the [[Configurable]] attribute must be true.
- If the target is non-extensible and P is non-existent, then all future calls to [[GetOwnProperty]] (P) on the target must describe P as non-existent (i.e. [[GetOwnProperty]] (P) must return undefined).
NOTE 2 As a consequence of the third invariant, if a property is described as a data property and it may return different values over time, then either or both of the Desc.[[Writable]] and Desc.[[Configurable]] attributes must be true even if no mechanism to change the value is exposed via the other internal methods.
译文: [[GetOwnProperty]] (P)
- 该方法的返回值类型必须是Property Descriptor(规则定义类型,用于规则的使用说明而定义的一些类型,不参与实际的编程过程)或Undefined(语言类型);
- 如果返回值的类型是Property Descriptor,则该值必须包括属性值完整的描述。
- 如果属性参数P是一个被定位数据属性的属性,并且其Desc.[[Value]] 的值等于v,Desc.[[Writable]]和Desc.[[Configurable]] 两个描述特性都是false,那么未来任何针对[[GetOwnProperty]] ( P )的调用,都必须返回与Desc.[[Value]] 特性所定义的相同的值v。
- 如果P除了[[Writable]]特性以外的其他特性会随着时间改变或者属性可能会不存在,那么P的.[[Configurable]]特性必须为true;
- 如果[[Writable]]特性可以从false改变为true,那么[[Configurable]]特性必须为true;
- 如果目标对象是不可扩展的,并且属性P是不存在的,那么未来该目标对象针对 [[GetOwnProperty]](P) 的所有调用都必须将P设置为不存在的(即返回undefined)。
注释2 作为上述第三条的结论,如果一个属性是数据属性并且可能会根据时间返回不同的值,那么Desc.[[Writable]]和Desc.[[Configurable]] 两者或者其中之一必须是true,即便是没有提供通过其他内部方法来进行修改值的机制。
原文:[[DefineOwnProperty]] (P, Desc)
- The Type of the return value must be Boolean.
- [[DefineOwnProperty]] must return false if P has previously been observed as a non-configurable own property of the target, unless either:
-
- P is a non-configurable writable own data property. A non-configurable writable data property can be changed into a non-configurable non-writable data property.
- All attributes in Desc are the SameValue as P's attributes.
- [[DefineOwnProperty]] (P, Desc) must return false if target is non-extensible and P is a non-existent own property. That is, a non-extensible target object cannot be extended with new properties.
译文:[[DefineOwnProperty]] (P, Desc)
- 该方法返回值必须为Boolean类型
- 如果参数P预先被设为目标对象的一个不可配置(non-configurable)的自有属性,那么该方法必须返回false, 但以下两种情况除外:
- P是一个不可配置,但是可以写入(writable)的自有属性,一个不可配置但是可写入的数据属性可以被改变为不可配置不可写入(non-writable)的数据属性;
- 所有参数二Desc中定义的特性值与P中原有的特性值都是完全一致的。
- 如果目标对象是不可扩展的并且P是不存在的自有属性,则该方法必须返回false,即一个不可扩展的对象是不能添加新属性的。
原文:[[HasProperty]] ( P )
- The Type of the return value must be Boolean.
- If P was previously observed as a non-configurable data or accessor own property of the target, [[HasProperty]] must return true.
译文:[[HasProperty]] ( P )
- 该方法必须返回Boolean类型
- 如果参数P已被定义为目标对象的一个不可配置(non-configurable)的数据或访问器类型自有属性,则该方法必须返回true。
原文:[[Get]] (P, Receiver)
- If P was previously observed as a non-configurable, non-writable own data property of the target with value v, then [[Get]] must return the SameValue.
- If P was previously observed as a non-configurable own accessor property of the target whose [[Get]] attribute is undefined, the [[Get]] operation must return undefined.
译文:[[Get]] (P, Receiver)
- 如果参数P是目标对象定义的不可配置且不可写入的自有数据属性,同时值为v,则该方法必须返回相同的值v;
- 如果P是目标对象定义的不可配置的访问器属性并且其[[Get]]特性未定义,则该方法操作必须返回undefined。
原文:[[Set]] ( P, V, Receiver)
- The Type of the return value must be Boolean.
- If P was previously observed as a non-configurable, non-writable own data property of the target, then [[Set]] must return false unless V is the SameValue as P's [[Value]] attribute.
- If P was previously observed as a non-configurable own accessor property of the target whose [[Set]] attribute is undefined, the [[Set]] operation must return false.
译文:[[Set]] ( P, V, Receiver)
- 该方法返回值类型必须是Boolean
- 如果参数P是目标对象定义的不可配置且不可写入的自有数据属性,则该方法必须返回false,除非参数V的值与P的[[Value]]特性的值是完全一致的。
- 如果P是目标对象定义的不可配置的访问器属性并且其[[SET]]特性未定义,则该方法操作必须返回false。
原文:[[Delete]] ( P )
- The Type of the return value must be Boolean.
- If P was previously observed to be a non-configurable own data or accessor property of the target, [[Delete]] must return false.
译文: [[Delete]] ( P )
- 该方法返回值类型必须为Boolean
- 如果参数P已被定义为目标对象的一个不可配置(non-configurable)的数据或访问器类型自有属性,则该方法必须返回false
原文:[[OwnPropertyKeys]] ( )
- The return value must be a List.
- The returned list must not contain any duplicate entries.
- The Type of each element of the returned List is either String or Symbol.
- The returned List must contain at least the keys of all non-configurable own properties that have previously been observed.
- If the object is non-extensible, the returned List must contain only the keys of all own properties of the object that are observable using [[GetOwnProperty]].
译文:[[OwnPropertyKeys]] ( )
- 该方法返回值必须是一个List(规则类型),等同一个Array(语言类型);
- 返回的List值必须不能包含任何重复或复制的实例;
- 返回的List中的每一个元素只能是String类型或是Symbol类型;
- 返回的List必须至少包括所有已知的不可配置自有属性的键;
- 如果对象是不可扩展的,则返回List必须只能包含能够被[[GetOwnProperty]]方法获得的所有自有属性的键。
原文:[[Construct]] ( )
- The Type of the return value must be Object.
译文:[[Construct]] ( )
更多内容,欢迎访问个人网站