I have a "class" Game
definding a game and an inner "class" Snake
defining a player in the game. My problem is that the member links
in my Snake
is showing as undefined
whenever the move
function is called and I can't figure out why this is.
Here's the Game
definition (with a lot stripped out for readability). If needed, I can do a complete code dump.
function Game ( board, numBlocks )
{
// ...
this.speedMap = { "fast": 100, "medium": 300, "slow": 600 };
this.curSpeed;
this.mover;
// ...
this.Snake = function ( game )
{
this.links;
this.dx;
this.dy;
this.createNew = function ( )
{
this.dx = 0; this.dy = 0;
this.links = [];
// ...
}
this.move = function ( )
{
console.log(this.links); // test
// ^ That is printing 'undefined'! Didn't I initialize it in 'createNew', though????
// ...
}
}
this.startNew = function ( spd )
{
// ...
this.snake = new this.Snake(this);
this.snake.createNew();
// ...
this.curSpeed = spd;
this.mover = setInterval(this.snake.move, this.speedMap[this.curSpeed]);
}
}