suchen

Heim  >  Fragen und Antworten  >  Hauptteil

请教一下这个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?

PHPzPHPz2849 Tage vor628

Antworte allen(1)Ich werde antworten

  • 怪我咯

    怪我咯2017-04-11 11:54:06

    child.uber = parent.prototype = {}

    Antwort
    0
  • StornierenAntwort