Hey guy's,
im pretty new to oop JS programming. Here is my problem:
Code:
function Ships(){
this.speed=1
}
Ships.prototype.faster=function{
this.speed=this.speed+1
}
function Ship(color){ //Child of Ships
Ships.call(this);// Call the parent constructor
this.color=color; //Color for the Ship. Used in JS Code
}
Ship.prototype = new Ships();// inherit Ships
Ship.prototype.constructor=Ship;// correct the constructor pointer
ship.prototype.animate = function(){
alert(this.speed)
}
As you see, ship should be a child of ships. Now the problem is that if i call ships.faster() the child function ship.animate() accesses an old value of this.speed.
how can i access the right mother object?
Thank you!