posts[0].show(); で console.log() が実行されるのはなぜですか?

show メソッドの中で console.log() が実行されるためです。
2021年7月29日
ユーザー

お世話になります。

const posts = [
    {
      text: 'JavaScriptの勉強中…',
      likeCount: 0,
      show() {
        console.log(`${this.text} - ${this.likeCount}いいね`);
      },
    },
    {
      text: 'プログラミング楽しい!',
      likeCount: 0,
      show() {
        console.log(`${this.text} - ${this.likeCount}いいね`);
      },
    },
  ];

  posts[0].show();
  posts[1].show();

上記において、なぜposts[0].show();で呼び出すことができるのでしょうか?
なんとなくでしか理解できていないので、詳しい解説をお願いしたいです。

この回答を見るにはプレミアムサービスへの登録が必要です

プレミアムサービスとは?