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);