为什么下面的代码中c.aname的值是undefined,而不是animal?难道书上的错了吗?
按照书上的例子,我写了一个function的继承的例子,发现和书上的结果不一样,我是用chrome浏览器测试的。
具体如下:
function Animal(){
this.aname='animal';
};
function Cat(){
this.age=12;
};
var F=function(){};
F.prototype=Animal.prototype;
Cat.prototype=new F();
var c=new Cat();
console.log(c.aname);//我测试的结果是undefined,而书上是animal
谁可以帮忙解答一下,多谢了。