【发布时间】:2015-11-26 09:19:14
【问题描述】:
<html>
<body>
<script>
function animal(kane){
this.kane:"aaaaa";
}
function Rabbit(name) {
this.name = name;
}
Rabbit.prototype.__proto__=animal.prototype;
var a=new animal("aaaa");// this wont work when i put a alert box
var rabbit = new Rabbit('John');
alert( rabbit.kane );// i should get aaaa but i am getting undefined
</script>
</body>
</html>
我应该在警告框中得到 aaaa,但我该怎么做 这种情况下的原型继承 何时使用 animal.prototype 以及何时使用 new animal()
【问题讨论】:
-
animal应该如何处理它所采用的kane参数?
标签: javascript prototype prototype-programming