function extend(subClass,superClass) { //初始化一个中间空对象,为了转换主父类关系 var F = function() {}; F.prototype = superClass.prototype; //让子类继承F subClass.prototype = new F(); subClass.prototype.constructor = subClass; //为子类增加属性superClass subClass.superClass = superClass.prototype; //增加保险,即使原型是超类Object,那句要把构造函数级别降下来 if(superClass.prototype.constructor == Object.prototype.constructor) { superClass.prototype.constructor = superClass; } } function Author(name,book) { Author.superClass.constructor.call(this,name); this.book = book; this.getBook = function() { return this.name + '--' + this.book; } } function Person(name) { this.name = name; } extend(Author,Person); var peter = new Author('long','keke'); console.log(peter.getBook())