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

你可能感兴趣的文章
php5 升级 php7 版本遇到的问题处理方法总结
查看>>
PHP5.3.3安装Mcrypt扩展
查看>>
PHP5.4 + IIS + Win2008 R2 配置
查看>>
PHP5.4 pfsocketopen函数判断sock是否存活的bug(由memcached引起)
查看>>
Redis从入门到精通
查看>>
PHP5.6.x编译报错:Don't know how to define struct flock on this system, set --enable-opcache=no
查看>>
php5ts.dll 下载_php5ts.dll下载
查看>>
php7
查看>>
PHP7 新特性
查看>>