PDA

View Full Version : Inheritance Subtleties?


Trinithis
07-07-2007, 02:52 AM
As far as I can tell, the following do exactly the same thing:


function House(location, cost) {
this.location = location;
this.cost = cost;
}

function Mansion(location, cost, size) {
this.parent = House;
this.parent(location, cost);
this.size = size;
}




function House(location, cost) {
this.location = location;
this.cost = cost;
}

function Mansion(location, cost, size) {
House.call(this, location, cost); //Or similarly with apply()
this.size = size;
}


Are there any differences whatsoever? If so, which technique is better?

Twey
07-07-2007, 12:36 PM
Nope, no differences at all (other than the obvious, that the latter creates a parent property).