博客
关于我
回想继承、原型与原型链有感
阅读量: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/

你可能感兴趣的文章
Objective-C实现字符串Z 函数或 Z 算法(附完整源码)
查看>>
Objective-C实现字符串加解密(附完整源码)
查看>>
Objective-C实现字符串反转(附完整源码)
查看>>
Objective-C实现字符串复制功能(附完整源码)
查看>>
Objective-C实现字符串是否回文Palindrome算法 (附完整源码)
查看>>
Objective-C实现字符串查找子串(附完整源码)
查看>>
Objective-C实现守护进程(附完整源码)
查看>>
Objective-C实现完整的ComplexNumber复数类(附完整源码)
查看>>
Objective-C实现完整的matrix矩阵类(附完整源码)
查看>>
Objective-C实现实现rabin karp算法(附完整源码)
查看>>
Objective-C实现对图像进行色调处理算法(附完整源码)
查看>>
Objective-C实现对称矩阵压缩存储(附完整源码)
查看>>
Objective-C实现寻找Find Lcm最小公倍数算法(附完整源码)
查看>>
Objective-C实现寻找无向图的关节点Articulation Points算法(附完整源码)
查看>>
Objective-C实现寻找欧拉路径/回路(附完整源码)
查看>>
Objective-C实现导弹跟踪算法(附完整源码)
查看>>
Objective-C实现将 b 除以模 n 的有效算法(附完整源码)
查看>>
Objective-C实现将 base64 字符串转换为字节数组算法(附完整源码)
查看>>
Objective-C实现将两个给定的字符串以O(n)的时间复杂度排列在一个字符串中算法(附完整源码)
查看>>
Objective-C实现将位转换为浮点数bitsToFloat算法(附完整源码)
查看>>