function myClass(a , b) {
this.a = a ;
this.b = b;
this.toString = function() {
return this.a + "," + this.b;
};
}
var obj = new myClass('hello' , 'world');
alert(obj);
打印的是hello,world.
this.toString=function() {
return this.a + "," + this.b;
};
等同于
myClass.prototype.toString = function() {
return this.a + "," + this.b;
};
看视频猜的,不知道对不对 ,感觉javascript很奇怪,也很博大精深,看来一声都得用功夫啊