<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title></head><body><script>// 直接替换原型对象function Person(name, age) {this.name = name;this.age = age;}var parent = {sayHello: function () {console.log("方式1:替换原型对象");}}Person.prototype = parent;var p = new Person("张三", 50);// p.sayHello();console.log(p)// 混入式原型继承function Student(name, age) {this.name = name;this.age = age;}var parent2 = {sayHello: function () {console.log("方式2:原型继承之混入式加载成员");}}for (var k in parent2) {Student.prototype[k] = parent2[k];}var p2 = new Student("张三", 50);// p.sayHello();console.log(p2)</script></body></html>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。