Is it correct to invoke the constructor of a JavaScript Object in one of the prototype functions?

I am reviewing a JavaScript code from a colleague and he wrote an Object prototype function that I believe is not correct regarding the principles of Object-Oriented Programming.

Game.prototype.reset = function() {
    if (game.over) {
        game.over = false;
        game = new Game(players);
    }    
}

A couple of lines below, the game variable was declared as a global variable.

var game = new Game(players);

So, is it correct to create a new Game object from one of its constructors? The code perfectly runs. Thanks!


Source: oop

Leave a Reply