About the data properties and accessor properties of an object

Source: Internet
Author: User

There are two types of properties in ECMAScript: Data properties and accessor properties.

Data properties:The Data property contains the position of a data value, where the value can be read and written.     The data attribute has 4 attributes that describe its behavior. 1. [[Configurable]] 2.     [[Enumerable]] 3. [[Writable]] 4. [[Value]] to modify the property's default attribute, you must use the Object.defineproperty () method. This method receives three parameters, the object where the property resides, the name of the property, and a descriptor object. Where the properties of the Descriptor object must be: Configurable, enumerable, writable, and value. For example: var person = {};object.defineproperty (person, "name", {writable:false,//note is comma value: "Nicholas"} Note: you can Modify enumerable, writable, and value in multiple calls to the Object.defineproperty () method, but for configurable, if set to false, it can no longer be modified. Additionally, when you call the Object.defineproperty () method, the default value of the writable attribute is False if you do not specify configurable, enumerable. Accessor properties can only be accessed through an object method, with the following four attributes: 1.     [[Configurable]] 2. [[Enumerable]] 3.     [[Get]] 4. [[Set]] In addition, the accessor property contains getter and setter functions.

About the data properties and accessor properties of an object

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.