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