JS Object literal

Source: Internet
Author: User

1.What

JS object literal in peacetime work with not much, but at least contact, worship the big God's JS code, with the majority of object literal, ashamed, today just know the name of this type of writing.

Object literals are a simple and easy-to-read way to create objects. An object was created as follows.

var obj = {    A:' aaa ',//A is a property, ' AAA ' is the attribute value    B: ' BBB ',    C:' CCC ' }obj.a//"AAA"obj[' a ']//"AAA "

2.Why

The so-called existence is reasonable. Why the existence of such a writing, Baidu has a circle, the wording of the mixed.

The general advantages are the following points:

    • Fast initialization of objects
    • Attribute sharing (unknown sensation)

3.How

An object literal is a list of 0 or more property name-value pairs (elements) that are enclosed in curly brace pairs ({}). You cannot use object literals at the beginning of a statement, which results in an error or unexpected behavior, because the left curly brace ({) is considered to be the starting symbol for a block of statements.

functionrelatedselect (config) { This. DefaultText =NULL;  This. defaulttextlist = [];  This. Firstparentcode = ";  This. url =NULL;  This. Resultproperty =NULL;  This. data =NULL;  This. Ispreappend =false;  This. Renderid =NULL;  This. NameList = [];  This. Prelabel = [];  This. Suflabel = [];  This. Listeners ={onRender:NULL, OnChange:NULL,    }}
Rspopulation =NewRelatedselect ({defaulttext:defaulttext, Firstparentcode:‘‘, Data:result.list, Listeners: {onRender:function(select) {varSelectsize =select.idList.length;  for(vari=0; i<selectsize; i++){                    varCurselect = $ (' # ' +(select.idlist) [i]+ ' option[value!= ' ""]); if(curselect!=NULL&& Curselect.length = = 1){                        $(' # ' +(select.idlist) [i]+ ' option[value!= ' "] ') [0].selected =true;                    Select.onchange (Select.getbyindex (i), i); }            }        }    }});

JS Object literal

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.