I have following script
<script>
var Animal = function(name){
this.name = name;
}
Animal.prototyp e.eat = function (food)
{
alert(this.name + " eat " + food);
}
//constructor for Dog
var Dog = function(){
}
//"inheriting " from Animal
Dog.prototype = new Animal();
Dog.prototype.c onstructor = Animal;
var myDog = new Dog("ddd");
myDog.eat("bone ");
</script>
The result was that Dog's constructor was called but Animal's constructor
was never called so I got "undefined eat bone".
Is the javascript inheritant doesn't support calling super constructor or
I didn't use "Dog.prototype. constructor" correctly?
thanks
<script>
var Animal = function(name){
this.name = name;
}
Animal.prototyp e.eat = function (food)
{
alert(this.name + " eat " + food);
}
//constructor for Dog
var Dog = function(){
}
//"inheriting " from Animal
Dog.prototype = new Animal();
Dog.prototype.c onstructor = Animal;
var myDog = new Dog("ddd");
myDog.eat("bone ");
</script>
The result was that Dog's constructor was called but Animal's constructor
was never called so I got "undefined eat bone".
Is the javascript inheritant doesn't support calling super constructor or
I didn't use "Dog.prototype. constructor" correctly?
thanks
Comment