I have an object called game in javascript. It creates another object called board. It then calls the move function in the board object. However, the board class uses animation. How do I send a callback function from the game object to the board object to be invoked by the board object?
I tried
var game = new Game();
game.play()
function Game() {
this.board = new Board();
var callback = function () {
this.doSomething();
// put something here
}
this.play = function () {
this.board.move(this.callback);
}
}
function Board() {
this.move = function (callback) {
callback();
}
}
But I get an error that this.doSomething is not defined.
Is there a way to call a function of another object from an object? Is there a way to call a function of a Game object in the Board object function?