2024年7月1日解決済み

check メソッドを Game クラス内に書いてもよいですか?

ユーザー

Game クラス内に check メソッドを作って、Panel クラスはclass 属性の追加メソッドを作る。

class Game {
    check(clickNum) {
      if (this.currentNum !== clickNum) return false;

      if(this.currentNum >= 3) {
        clearTimeout(this.timeoutId);
      }
      this.currentNum++;
      return true;
    }   
}
class Panel {
    constoructor(game) {
        this.el.addEventListener('click', () => {
                if(game.check(Number(this.el.textContent))) this.addPressed();
            });
    }

    addPressed() {
        this.el.classList.add('pressed');
    }
}

この書き方ではダメですか?

スタッフ

この回答を見るにはプレミアムプランへの登録が必要です

プレミアムプランとは?