创建对象
var car = new Object();
var car = {};
var car = {
color : "red",
run : function(){alert("run")}
};
car.color; //"red"
car.run();//alert("run")
car["color"];
car["run"]();
增加属性和方法
car.type = "suv";
修改
car.color = "white";
删除
delete car.color;
元素构建
car.constructor; //Object
constructor
var num = new Number(123);
num.constructor;//Number
toString
var num = new Number(123);
num.toString() //"123"
valueOf
var num = new Number(123);
num.valueOf(); //123
hasOwnProperty
var car = {
color : "red",
run : function(){alert("run")}
};
car.hasOwnProperty("color") //true
car.hasOwnProperty("logo") //false
网友评论