2021年8月5日解決済み

Panel クラスで Game クラスのインスタンスを作っても良いのでしょうか?

ユーザー
class Panel {
    constructor(game) {
      this.game = game;  => this.game = new Game();
      this.el = document.createElement('li');
      this.el.classList.add('pressed');
      this.el.addEventListener('click', () => {
        this.check();
   });
}

上記のコードにように、コンストラクタに仮引数を渡すではなく、その中で Game のインスタンスを作ればプロパティにもアクセスできるですが、なぜそうしないですか?

スタッフ

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

プレミアムプランとは?