- JS對象冒充為什麼不能繼承屬性?
-
function Animal(name,age){
this.name=name;
this.age=age;
this.eat=function(){
alert ("小明吃吃吃");
}
}
function Dog(name,age){
this.song=Animal;
this.song(name.age);
}
var dog1=new Dog("小明",27);
dog1.eat();
alert (dog1.age);
alert (dog1.name);
最佳回答:
this.song(name.age);
===>
this.song(name,age); 別寫錯符號了,是逗號