构造函数:
1function info(id, name)
2{
3 this.id = id;
4 this.name = name;
5}
构造对象:2{
3 this.id = id;
4 this.name = name;
5}
var info1 = new info(1,'ab');
或者
var info = {id:1;name:'ab'};
删除对象的属性:
js 1.2之后:delete info.name;
js 1.2之前可以用这些方法使一个属性失效:
info.name = null;
或者把属性设置成未定义,只需要把一个没定义的属性赋给它:info.name = info.namemm;
或者把更巧妙的使用void运算符生成一个未定义的值:
info.name = void 0;
枚举对象的属性:
for(var i in info)
{
alert(i);
}
给类添加方法:{
alert(i);
}
//方法
function show(name)
{
alert(name);
}
//新构造函数
function info(id,name)
{
this.id = id;
this.name = name;
//method
this.show = show;
}
function show(name)
{
alert(name);
}
//新构造函数
function info(id,name)
{
this.id = id;
this.name = name;
//method
this.show = show;
}