Standard procedure for JavaScript object initialization (object literal)-based on ECMAScript-262 V5.1

Source: Internet
Author: User
Tags closure
Object Initialization (English Source: ECMAScript-262 Fifth Edition)

(Huang Di for commentary or vacancy)
中文版

Object initialization is an expression that describes the initialization process of an object in a direct amount of terms. It is a list of 0 or more pairs of attribute name/association values enclosed in curly braces, and values do not need to be direct, and they are executed once each time the object initialization is executed.

Grammar:

   objectliteral : {} {} {}
        
       //ecma-262 does not prohibit the endtoadd commas!
       
   propertynameandvaluelist :
       propertyassignment
       , propertyassignment
   propertyassignment :
       : assignmentexpression get
       () {}
       set () {}
   PropertyName :
       identifiername
       stringliteral
       numericliteral
   propertysetparameterlist :
       Identifier

Semantic:

The resulting objectliteral: {} executes as follows: Creates a new object and returns the object as an expression new () , where object is the standard built-in constructor.

Production S objectliteral: { propertynameandvaluelist} and objectliteral: { Propertynameandvaluelist, Follow the procedure below: Returns the result of interpreting the execution propertynameandvaluelist.

Production propertynameandvaluelist: propertyassignment Follow the procedure below: make obj equal to a newly created object, just as you would create a new object using new objects (), where Ob Ject is a standard built-in constructor. Instead of creating an object with the new object (), you get a new object in some way, but the result returned is the same as using the new object ().
Propid to explain the execution of propertyassignment results. Propid with parameters. name, Propid. descriptor and false invoke the [[Defineownproperty]] built-in method of obj. Returns obj.

Production Type Propertynameandvaluelist:Propertynameandvaluelist,Propertyassignment Follow the following procedure: Let obj perform the propertynameandvaluelist result for interpretation. obj is still a temporary object and does not return, so it is not accessible anywhere else in the literal code and does not point to obj obj,this.
Propid to explain the execution of propertyassignment results. The previous is propid as a parameter.nameThe result of invoking the [[Getownproperty]] built-in method of obj. If previous is notundefined, and when any one of the following conditions istrue, you throw aSyntaxErrorException: The production is contained in strict mode and Isdatadescriptor (previous) istrueand Isdatadescriptor (propid.Descriptor) istrue。 Isdatadescriptor (Previous) istrueand Isaccessordescriptor (propid.Descriptor) istrue。 Isaccessordescriptor (Previous) istrueand Isdatadescriptor (propid.Descriptor) istrue。 Isaccessordescriptor (Previous) istrueand Isaccessordescriptor (propid.Descriptor) istrueand previous and Propid.Descriptorhave [[get]] fields or previous and propid.DescriptorHas a [Set]] field.

Pass in the parameter propid.name,propid.descriptor, and false to the internal method [[Defineownproperty]] and execute. (Call [[[Defineownproperty]] internal method of obj with arguments propid.name, Propid.descriptor, and false.)

Returns the Obj object (return obj.)

If the above steps throw a syntaxerror, the implementation should treat this error as an early error.

Production Type propertyassignment: PropertyName:assignmentexpression Follow the following procedure: Make PropName perform PropertyName for interpretation The results. Exprvalue to explain the execution of assignmentexpression results. Make PropValue the GetValue (exprvalue). Make Desc A property description object {[[Value]]:p ropvalue, [[writable]]:true, [[Enumerable]]:true, [[Configurable]]: True}. Returns the property identifier (PROPNAME, desc).

The resulting propertyassignment: get PropertyName() {functionbody} is executed in the following procedure: to PropName for interpretation The result of PropertyName. The closure is a new function object created with an empty argument list and a functionbody function body, based on the definition of 13.2. Incoming lexicalenvironment as Scopefor the execution environment in the current execution. If the propertyassignment is included in the strict mode code or if the Functionbody is a strict mode code, pass true to the strict mode flag. Make Desc A property description object {[[Get]]:closure, [[Enumerable]]:true, [[Configurable]]:true}. Returns the property identifier (PROPNAME, desc).

Production propertyassignment: Set propertyname(propertysetparameterlist ) {functionbody} Follow the procedure below: Make propname perform propertyname results for interpretation. The closure is a new function object created by Propertysetparameterlist as a parameter list and functionbody function body, as specified in 13.2. Incoming lexicalenvironment as Scopefor the execution environment in the current execution. If the propertyassignment is included in the strict mode code or if the Functionbody is a strict mode code, pass true to the strict mode flag. Make Desc A property description object {[[Set]]:closure, [[Enumerable]]:true, [[Configurable]]:true}. Returns the property identifier (PROPNAME,DESC).

If Functionbody is a strict mode or is included in the strict mode code, the propertysetparameterlist in Propertyassignment,"eval" or "arguments" as an identifier will be a syntax error.

PropertyName: IdentifierName follows the following procedure: Returns a String value containing exactly the same sequence of characters as IdentifierName.

Production PropertyName: stringliteral Follow the following procedure: Returns the string value of StringLiteral.

Production PropertyName: numericliteral Follow the following procedure: Make NBR the result of seeking numericliteral value. Return ToString (NBR). Note: [[Defineownproperty]] is used to ensure that the array's own properties are defined even if the built-in Array.prototype is modified, which avoids the use of [[put]] To create a new self attribute.

Reference Links:

ECMA-262 11th Chapter Expression

Chinese translation link: Http://www.w3.org/html/ig/zh/wiki/ES5/%E8%A1%A8%E8%BE%BE%E5%BC%8F network beauty: the implementation of get and set accessors in javascript: http:// Www.cnblogs.com/lhb25/archive/2010/09/19/1830724.html


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.