为了账号安全,请及时绑定邮箱和手机立即绑定

有人给我解释下这个继承函数是如何工作的么?

有人给我解释下这个继承函数是如何工作的么?

慕哥9229398 2018-08-06 10:09:16
如题,下面是一个继承函数(子类可继承父类的属性及方法),但是不懂工作原理,求解,求科普,求链接。var extend = function(child, parent) {    for (var key in parent) {        if (hasProp.call(parent, key)) child[key] = parent[key];     }    function ctor() {        this.constructor = child;     }     ctor.prototype = parent.prototype;     child.prototype = new ctor();     child.__super__ = parent.prototype;    return child; }, hasProp = {}.hasOwnProperty;
查看完整描述

1 回答

?
千巷猫影

TA贡献1829条经验 获得超7个赞

查看完整回答
反对 回复 2018-09-19
  • 1 回答
  • 0 关注
  • 629 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号