博客
关于我
回想继承、原型与原型链有感
阅读量:450 次
发布时间:2019-03-06

本文共 909 字,大约阅读时间需要 3 分钟。

function People(name, age) {    this.name = name;    this.age = age;    this.eat = function () {        console.log(`${this.name}: people eat!`);    };}People.prototype.protoEat = function () {    console.log(`${this.name}: proto eat!!`);}; function Student(name, age) {People.call(this, name, age);Student.prototype.constructor = Student;} Student.prototype = new People();
function People(name, age) {this.name = name;this.age = age;this.eat = function () {console.log(${this.name}: eat!);};}People.prototype.protoEat = function () {console.log(${this.name}: proto eat!!);}; function Student(name, age) {People.call(this, name, age);} for (const key in People.prototype) {Student.prototype[key] = People.prototype[key];}
var obj = {name: "People",eat: function () {console.log("eat fn!");}}; function clone(obj) {const Fn = new Function();Fn.prototype = obj;return new Fn();} const tt = clone(obj);tt.eat();

转载地址:http://isufz.baihongyu.com/

你可能感兴趣的文章
python基础篇(8):字符串常用处理汇总
查看>>
python基础篇(7):函数进阶知识点
查看>>
python基础篇(6):global关键字
查看>>
python基础篇(5):None类型
查看>>
python基础篇(4):range语句
查看>>
python基础篇(3):print()补偿知识点
查看>>
python基础篇(2):字符串扩展知识点
查看>>
python基础篇(1):type()
查看>>
python基础篇(15):闭包
查看>>
python基础篇(14):多态
查看>>
python基础篇(13):类型注解
查看>>
python基础篇(12):继承
查看>>
python基础篇(11):封装
查看>>
python基础篇(10):自定义包
查看>>
python基础篇(10):类、对象与构造方法
查看>>
python系列【仅供参考】:python测试javaSDK总结
查看>>
python系列【仅供参考】:python斗地主
查看>>
Python基础教程(第2版 修订版) pdf
查看>>
python基础实践(四)
查看>>
Python基础学习笔记(九)常用数据类型转换函数
查看>>