Closed xiaokaixuan closed 5 years ago
function Animal() { this.name = 'animal'; } function Cat(name) { Animal.call(this); this.name = name || 'Tom'; } (function (d, b) { function __() { this.constructor = d; } __.prototype = b.prototype; d.prototype = new __(); })(Cat, Animal);
或
function Animal() { this.name = 'animal'; } function Cat(name) { Animal.call(this); this.name = name || 'Tom'; } require('util').inherits(Cat, Animal); // <=> Cat.super_ = Animal; Object.setPrototypeOf(Cat.prototype, Animal.prototype);
或