JavaScript Property Type (data property accessor property)

Source: Internet
Author: User

ECMA-2 defines an object as: "A collection of unordered attributes whose properties can contain basic values, objects, or functions." ”

Strictly speaking, this is equivalent to saying that the object is a set of values that do not have a particular order. An object's properties or methods have a name, and each name maps to a value. We can think of the ECMAScript object as a hash table, nothing more than a set of name-value pairs, where values can be data or functions. (Gao Cheng P139)

Translation Properties of objects in JavaScript "Gao Cheng P139 attribute type" JavaScript notes-data properties and accessor properties

There are two different types of properties in javascript: named data attributes (named Data properties), named accessor properties (named Accessor properties), and internal attributes (internal properties).

Named Data properties

The Named Data property contains the location of a data value. Values can be read and written at this location.

Data attributes have four properties describing their behavior (attribute)

    • [[Configurable]] Boolean value that indicates whether the property can be redefined by deleting the property, and whether the attribute can be modified to modify the property to an accessor property. Properties defined directly on the object , default to True
    • [[Enumerable]] Boolean value, whether the property can be returned through a for-in loop.
    • A [[writable]] Boolean value that indicates whether the value of the property can be modified. (That is, whether it is read-only)
    • [[Value]] property value
Named Accessor properties

Accessor properties have four attributes:

    • [[Configurable]] Boolean value that indicates whether the property can be redefined by deleting the property, and whether the attribute can be modified to modify the property to an accessor property. Properties defined directly on the object , default to True
    • [[Enumerable]] Boolean value, whether the property can be returned through a for-in loop.
    • The function that is called when this property is read [[Get]]. Getter function
    • [[Set]] The function to invoke when assigning a value to this property. Setter functions
Internal properties

Some properties are only used for specifications, called internal properties, because they are not directly accessible through JavaScript, but they do exist and affect the performance of the program. The names of the internal properties are special, and they are surrounded by two brackets. Here are two examples:

    • The internal property [[[Prototype]] points to the prototype of the owning object. The value of this property can be read to by the object.getprototypeof () function . The value of this property can only be passed when a new object is created Object.create () or __proto__ to set .
    • The internal property [[extensible]] Determines whether a new property can be added to the owning object. The value of this property can be read through object.isextensible () . You can also Object.preventextensions () Sets the value of this property to False. Once set to false, it is no longer possible to set back to true .
Default value for attribute (attribute)

If you do not explicitly specify a value for an attribute, they will be assigned a default value:

[[Value]] undefined

[[Get]] undefined

[[Set]] undefined

[[Writable]] false

[[Enumerable]] false

[[Configurable]] false

JavaScript Property Type (data property accessor property)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.