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
| function Parent (name) { this.name = name }
Parent.prototype.play = function() { console.log('play' + this.name) } function Child (name,age) { Parent.call(this, name) this.age = age }
Child.prototype = new Parent() Child.prototype.constructor = Child
Child.prototype = Object.create(Parent.prototype) Child.prototype.constructor = Child let children = new Child('tom') children.play()
|