NIUCLOUD是一款SaaS管理后台框架多应用插件+云编译。上千名开发者、服务商正在积极拥抱开发者生态。欢迎开发者们免费入驻。一起助力发展! 广告
[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 ```