面向对象编程
function inherits(Child,Parent){ var F = function(){}; F.prototype = Parent.prototype; Child.prototype = new F(); Child.prototype.constructor = Child; } function Student(props){ this.name = props.name || 'WangXiang'; }; Student.prototype.hello = function(){ alert('Hello,' + this.name + '!') }; function PrimaryStudent(props){ Student.call(this,props); this.grade = props.grade || 43; } inherits(PrimaryStudent,Student); PrimaryStudent.prototype.getGrade = function(){ return this.grade; }