javascript最常用的对象创建方式

时间:2022-02-05 21:49:51
 //第一种
function Demo(){
var obj=new Object();
obj.name="Yubaba";
obj.age=12;
obj.firstF=function(){
}
obj.secondF=function(){
}
return obj;
} var one=Demo();
// 调用输出
document.write(one.age);

 //第二种
function Demo(){
this.name="Yubaba";
this.age=12;
this.firstF=function(){
}
this.secondF=function(){
}
} var one=new Demo // 调用输出
document.write(one.age);

相关文章