当前位置: 移动技术网 > IT编程>开发语言>JavaScript > javascript最常用的对象创建方式

javascript最常用的对象创建方式

2019年01月15日  | 移动技术网IT编程  | 我要评论
 1 //第一种
 2 function demo(){
 3     var obj=new object();
 4     obj.name="yubaba";
 5     obj.age=12;
 6     obj.firstf=function(){
 7     }
 8     obj.secondf=function(){
 9     }
10     return obj;
11 }
12 
13 var one=demo();
14 // 调用输出
15 document.write(one.age);

 1 //第二种
 2 function demo(){
 3     this.name="yubaba";
 4     this.age=12;
 5     this.firstf=function(){
 6     }
 7     this.secondf=function(){
 8     }
 9 }
10 
11 var one=new demo
12 
13 // 调用输出
14 document.write(one.age);

 

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网