参数版-----------------------------------------------
function Rect(width, height){
this.width = width;
this.height = height;
this.area = function(){return this.width*this.height;};
}
function myRect(width, height, name){
Rect.call(this,width,height);
this.name = name;
this.show = function(){
alert(this.name+” with area:”+this.area());
}
}
对象版---------------------------------------
function Rect(config){
this.width = config.width;
this.height = config.height;
this.area = function(){return this.width*this.height;};
}
function myRect(config){
Rect.call(this,config);
this.name = config.name;
this.show = function(){
alert(this.name+" with area:"+this.area());
}
}
var a =new myRect({width:1,heigth:2,name:3});
var b =a.width;
alert(b);