Assuming you have two objects -
Code:
var motherShip = new Ships();
var childShip = new Ship();
And then you are trying to call the faster() function of parent object, and want that value to be reflected in your child object... something like below -
Code:
motherShip.faster(); // this will set speed = 2
childShip.animate(); // this is still referring to speed = 1
If above assumptions are correct, and that is how you are calling the functions, then I am sure it wont achieve the expected result.
Reason:
When you create two objects, two different memory space is created for all variables and methods defined in those objects. So, in this case, two different variables "speed" are created for two different objects - motherShip and childShip.
If you want to access the parent variable in the child object, you need to call the parent method using child object only.
So, the code would be something like shown below -
Code:
childShip.faster(); // this will set speed = 2
childShip.animate(); // this will now refer to speed = 2
Can you please provide how you are defining the objects and calling the functions?
Hope this may help you out...
Regards,
Niral Soni