function f(name,age){ this.name=name; this.age=age; this.addAge=function(){alert("cheng")}; } var p=new f("tom",12); alert(p.name); var s=new f("tom",16); s.city="shandong"; alert(p.city); alert(typeof(s.city));
实验证明,只会给对象增加属性,而不会给类增加属性
function f(name,age){ this.name=name; this.age=age; this.addAge=function(){alert("cheng")}; } var p=new f("tom",12); alert(p.name); var s=new f("tom",16); s.city="shandong"; alert(p.city); alert(typeof(s.city));