{属性名:属性值,属性名:属性值~~~}
{ x:2,y:1 }//属性名是标识符{ "x":2,"y":1 }//属性名是字符串值{ 'x':2,'y':1 }//属性名是字符串值{ 1:2,2:1 }//属性名是数值{ x:2,y:1, enable:ture,color:{r:255,g:255,b:255} }//属性名是各种类型的属性值
{ x:2,y:1 }//属性名是标识符
{ "x":2,"y":1 }//属性名是字符串值
{ 'x':2,'y':1 }//属性名是字符串值
{ 1:2,2:1 }//属性名是数值
{ x:2,y:1, enable:ture,color:{r:255,g:255,b:255} }//属性名是各种类型的属性值
{x:2,y:1,}
var obj={x:3,y:4};document.write(typeof obg);/*输出:object*/
var obj={x:3,y:4};
document.write(typeof obg);
/*
输出:
object
*/
var ojb={x;3,y:4};document.write(ojb.x)/*输出:3*/
var ojb={x;3,y:4};
document.write(ojb.x)
3
var obj={pos:{x:3,y:4}}document.write(obj.pos.x);/*输出:3*/
var obj={pos:{x:3,y:4}}
document.write(obj.pos.x);
var obj={x:3,y:4};obj.x=33;document.write(obj.x);/*输出:33*/
obj.x=33;
document.write(obj.x);
33
var obj={x:2,y:4};obj.z=5;document.write(obj.z);/*输出:5*/
var obj={x:2,y:4};
obj.z=5;
document.write(obj.z);
5
var obj={x:3,y:4};document.write(obj[x]);/*输出:3*/
document.write(obj[x]);
var obj={x:3,y:4};var name='x';document.write(obj[name]);/*输出:3*/
var name='x';
document.write(obj[name]);
var obj={x:3,y:4};obj['5']=5;//若不存在则新建一个属性document.write(obj[5]);/*输出:5*/
obj['5']=5;//若不存在则新建一个属性
document.write(obj[5]);
var obj.fn=function(a,b){ return Number(a)+Number(b);}document.write(obj.fn(3,4))/*输出:7*///这样书写也是可以的var sum=function(a,b){ return Number(a)+Number(b);}var obj.fn=sum;document.write(obj.fn(3,4));/*输出:7*/
var obj.fn=function(a,b){
return Number(a)+Number(b);
}
document.write(obj.fn(3,4))
7
参考书籍资料:
1、javascript编程全解http://www.ituring.com.cn/book/1140
2、javascript 岳英俊http://pan.baidu.com/s/1eQlegKE