View Single Post
Old 01-02-2013, 12:53 PM   PM User | #1
explofish
New to the CF scene

 
Join Date: Jan 2013
Posts: 3
Thanks: 2
Thanked 0 Times in 0 Posts
explofish is an unknown quantity at this point
Post Object Orientated Problem

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!
explofish is offline   Reply With Quote