请教一下这个JavaScript的继承问题

查看:99
本文介绍了请教一下这个JavaScript的继承问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

将函数的继承封装成如下函数:

function extend(child, parent){
    var f = function(){}
    f.prototype = parent.prototype
    child.prototype = new f()
    child.prototype.constructor = child
    child.uber = parent.prototype
}

function Creature(){}
function Person(){}

extend(Person, Creature)

请教一下,这是访问Person.uber属性,为什么是undefined?

这个问题已被关闭,原因:问题已解决 - 问题已解决,且对他人无借鉴意义

解决方案

child.uber = parent.prototype = {}

这篇关于请教一下这个JavaScript的继承问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆