Add to
Such as: the use of an object called a description 狗蛋
of the man, first declare an object literal, to give the object properties and methods of evaluation;
var obj = { } ;
obj. name = '狗蛋' ;
obj. sayName = function ( ) {
console. log ( '你好,我叫' + obj. name) ;
}
When the object is initialized by the literal, initialization properties
var student = {
name : '狗蛋' ,
age : 12 ,
gender : '男' ,
sayName : function ( ) {
console. log ( student. name) ;
}
}
A property and a value called the key-value pair . A plurality of key-value property for the approach used between commas, bond:
var obj = { } ;
obj[ 'name' ] = '狗蛋' ;
obj[ 'sayName' ] = function ( ) {
console. log ( '你好,我叫' + obj[ 'name' ] ) ;
}