Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by MikeL

I am working on abstracting out my game flow control out of main.js and into it's own class - GameController. I have encountered a problem, whereby I want to call the parent function of the update method of MyGame, but from a method within the GameController class. Is this possible?

I tried:
    ig.game.update.parent();

and
      var update = ig.game.update;
      update.parent();

but I get a variation on this error:
Uncaught TypeError: Object function () {
var tmp = this.parent;
this.parent = parent[name];
var ret = fn.apply(this, arguments);
this.parent = tmp;
return ret;
} has no method 'parent'

1 decade ago by dominic

Well yes, but It's not pretty:
ig.Game.prototype.update.call( ig.game );

This calls the original update() method from ig.Game with the current game instance (ig.game - lowercase) as the this value. See Mozillas documentation for .call.

1 decade ago by MikeL

Yikes! Thanks so much for that Dominic! I was messing around with call afterwards and couldn't find the right way to do it. I'll take ugly any day here if it works. And thanks for the link.
Page 1 of 1
« first « previous next › last »