ThinkSSL🔒 一键申购 5分钟快速签发 30天无理由退款 购买更放心 广告
[TOC] ## 继承 ``` function create(proto) { function F() {} F.prototype = proto; return new F(); } // Parent function Parent(name) { this.name = name } // 父类方法 Parent.prototype.sayName = function () { console.log(this.name) }; // Child function Child(age, name) { Parent.call(this, name) this.age = age } // 继承父类方法 Child.prototype = create(Parent.prototype) // 子类方法 Child.prototype.sayAge = function () { console.log(this.age) } // 测试 const child = new Child(18, 'Jack') child.sayName() // Jack child.sayAge() // 18 ```