vendredi 23 février 2018

How to get parent class from inner var in Javascript?

I have class like this

class Game {
    constructor(player1, player2, gameId) {

        this.Clockk = {
            totalSeconds: timeForAnswer,
            nowSeconds: timeForAnswer,

            start: function () {
                var self = this;
                this.interval = setInterval(function () {
                    self.nowSeconds -= 1;
                    if (self.nowSeconds == 0) {

                          here I want to call "answered" function

                    }
            },

            reset: function(){
                this.nowSeconds = this.totalSeconds;
            },
        };

        answered(player) {
             console.log(player);
        }
    };

I want to call function of Game class from this.Clockk variable. this keyword inside a variable is this.Clockkitself, how can I get parrent class itself?




Aucun commentaire:

Enregistrer un commentaire