我想了解繼承在JavaScript執行Javascript繼承
function baseClass(name) {
this.name = name;
this.getName = function() {
return this.name;
}
}
function subClass(id, company){
baseClass.call(this);
this.id = id;
this.company = company;
this.toString = function() {
return name + "\n" + this.id + "\n" + this.company;
}
}
subClass.prototype = Object.create(baseClass);
var s = new subClass();
s.toString(); //here the name property from the baseClass is not displayed.
如何正確地實現繼承(經典/原型)
45分鐘前[可能重複](http://stackoverflow.com/questions/16020577/proper-prototypal-inheritance)。此外,忘了古典,因爲EcmaScript(javascript)是一種原型語言。 – GitaarLAB
「古典/原型」 - 你是指哪一個? – Pointy
沒有_classical_,因爲JavaScript是**原型**語言...... – War10ck