日期:2014-05-16 浏览次数:20465 次
function Odemo(name) { this.name1=name; this.sayName=sayName; //引用外面的函数 } function sayName() { return this.name1; } var a=new Odemo('aaa'); alert(a.sayName()); var b=new Odemo('bbb'); alert(b.sayName()); alert(a.sayName==b.sayName); //显示true
function Odemo(){} Odemo.prototype.name='abc'; Odemo.prototype.sayName=function() { return this.name; } var a=new Odemo(); alert(a.sayName()); //显示abc var b=new Odemo(); alert(b.sayName()); //显示abc alert(a.syaName==b.sayName); //显示false