💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
[https://segmentfault.com/a/1190000016708006](https://segmentfault.com/a/1190000016708006) ## 方式一、原型链继承 这种方式关键在于:**子类型的原型为父类型的一个实例对象。** ~~~ //父类型 function Person(name, age) { this.name = name, this.age = age, this.play = [1, 2, 3], this.setName = function () { } } Person.prototype.setAge = function () { } //子类型 function Student(price) { this.price = price this.setScore = function () { } } //Student.prototype默认是指向Object空对象的 Student.prototype = new Person() // 子类型的原型为父类型的一个实例对象 var s1 = new Student(15000) var s2 = new Student(14000) console.log(s1,s2) ~~~ ![](https://img.kancloud.cn/2b/c3/2bc38473369bd152a9abecad526778fc_833x452.png) ![](https://img.kancloud.cn/ca/a6/caa674d6c60ef4d7b4185032d8576e64_1319x537.png)