プロトタイプと継承

function Rectangle(w,h){
	this.width = w;
	this.height= h;
}

Rectangle.prototype.area = funnction(){
	return this.width * this.height;
}

var r = new Rectangle(2, 3);
r.hasOwnProperty("width"); //true
r.hasOwnProperty("area"); //false
"area" in r; //true

Post a Comment

Your email is never published nor shared.