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

你可能感兴趣的文章
php如何做表格,新手怎么制作表格
查看>>
RabbitMQ高级特性
查看>>
php如何定义的数位置,php如何实现不借助IDE快速定位行数或者方法定义的文件和位置...
查看>>
RabbitMQ集群 - 普通集群搭建、宕机情况
查看>>
php如何正确的获得文件的后缀名
查看>>
PHP如何生成唯一的数字ID
查看>>
PHP如何获取当前页面的最后修改时间
查看>>
PHP如何读取json数据
查看>>
PHP字符串
查看>>
PHP字符串递增
查看>>
php学习之基础语法
查看>>
RabbitMQ集群 - 仲裁队列、Raft协议(最详细的选举流程)
查看>>
PHP学习总结(11)——PHP入门篇之WAMPServer多站点配置
查看>>
PHP学习总结(12)——PHP入门篇之变量
查看>>
PHP学习总结(13)——PHP入门篇之常量
查看>>
PHP学习总结(14)——PHP入门篇之常用运算符
查看>>
PHP学习总结(1)——PHP入门篇之PHP可以做什么?
查看>>
PHP学习总结(2)——PHP入门篇之PHP代码标识
查看>>
PHP学习总结(3)——PHP入门篇之PHP的echo语句
查看>>
PHP学习总结(4)——PHP入门篇之PHP计算表达式
查看>>