6.1.2 Defining multiple properties

Source: Internet
Author: User

ECMAScript 5 also defines a object.defineproperties () method because there is a high likelihood that no object defines multiple properties. This method allows you to define multiple properties at once by using a descriptor. This method receives two object arguments: The first object is the object whose properties are to be added and modified, and the properties of the second object correspond to the property one by one to be added or modified in the first object. For example:

var book = {};object.defineproperties (book,{    _year:{        value:2004    },    edition:{        value:1    },    year:{        get:function () {            return this._year;        },        set:function (newvalue) {            if (newvalue >2004) {                this._year = newvalue;                This.edition + = newValue-2004;}}}    );

The above code defines two data attributes (_year and edition) and one accessor property (year) on the book object. The final object is the same as the object defined in the previous section. The only difference is that the properties here are created at the same time.

Browsers that support the Object.defineproperties () method are ie9+, ff4+, safari5+, opera12+, and Chrome.

6.1.2 Defining multiple properties

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.