1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
function inherit(Child, Parent) { function F(){}; F.prototype = Parent.prototype; Child.prototype = new F(); Child.prototype.constructor = Child; }
function Animal(legsNumber){ this.legsNumber = legsNumber; }
function Dog(){ this.name = name; Animal.call(this, 4); }
inherit(Dog, Animal);
Dog.prototype.kind = '狗' Dog.prototype.say = function(){ console.log(`汪汪汪~ 我是${this.name},我有${this.legsNumber}条腿。`) }
const d1 = new Dog('啸天') console.dir(d1)
|