Something is wrong in my code. I'm trying to start interval calling Prototype function in object contructor on new Tournament(). But node.js throwing an error: RangeError: Maximum call stack size exceeded.
When I'm not assinging timer to Tournament object, everything is fine. var timer = setInterval(); works good as well.
Could you please explain me?
var Tournament = function() {
var tournament = this;
console.log("Creating new instance.");
this.users = [];
this.state = 'waitingForPlayers';
this._id = generateId();
this.startTimer(6, tournament.startTournament);
};
Tournament.prototype.startTimer = function(time, timoutCallback) {
var tournament = this;
tournament.time = time;
tournament.timer = setInterval(function() {
tournament.time--;
console.log(Tournament.time);
if(tournament.time <= 0) {
clearInterval(tournament.timer);
timoutCallback();
};
}, 1000);
};
Tournament.prototype.startTournament = function() {
console.log("Tournament is starting.");
};
Edited:
I'm creating instance:
var tournament = new Tournament();
game.instances.push(tournament);