天天看點

JavaScript繼承的實作

JavaScript繼承有構造函數繼承、原型繼承、複制繼承、構造函數/原型組合繼承等方法,這些繼承方法各有特點。眼下最經常使用的就是構造函數/原型組合繼承。

<code></code>

<code>inherit(Student, Person); Student.prototype.setEducation = function(education){ this.education = education; }; Student.prototype.getEducation = function(){ return this.education; }; var person = new Person('小明', 25); var student = new Student('小剛', 22, '大學'); person instanceof Person; //true student instanceof Person; //true student instanceof Student; //true</code>

父類屬性及方法

JavaScript繼承的實作

子類屬性及方法

JavaScript繼承的實作