开发者

Why doesnt this javascript inheritance work? [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 10 years ago.

Im trying to get my head around javascript inheritance and this code doesnt work cant see why:

function Animal(){

  this.hasfur = true;

}

function Cat(){

  this.sound = "M开发者_JS百科eow";

}

$(document).ready(function(){

   Cat.protptype = new Animal();

  var myCat = new Cat();

  console.log(myCat.hasfur);


}

The console comes out with undefined. But I thought that when I access myCat.hasfur it should look at the prototype of cat which is vehicle and then look at that property...?


Read that again:

Cat.protptype

I'm pretty sure you meant:

Cat.prototype


It is just a typo at

Cat.protptype = new Animal();

write

Cat.prototype = new Animal();

instead.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜