Node.js examples for Object:Inheritance
Extend class
'use strict';//from ww w . ja v a 2 s . co m function extend(Child, Parent) { var F = function () {}; F.prototype = Parent.prototype; Child.prototype = new F(); Child.prototype.constructor = Child; } function Student(props) { this.name = props.name || 'Unnamed'; } Student.prototype.hello = function () { alert('Hello, ' + this.name + '!'); }; function PrimaryStudent(props) { Student.call(this, props); this.grade = props.grade || 1; } extend(PrimaryStudent, Student); PrimaryStudent.prototype.getGrade = function () { return this.grade; }; var pop = new PrimaryStudent(); console.log(pop.name());