1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| function Father(name) { this.name = name this.say = function () { console.log('hello,world'); } } Father.prototype.showName = function () { console.log(this.name); } function Son(name, age) { Father.call(this, name) this.age = age } Son.prototype = Object.create(Father.prototype) Son.prototype.constructor = Son const son = new Son('刘逍', 20) console.log(son.prototype.name);
|