2021年7月30日解決済み

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

ユーザー

お世話になります。

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();で呼び出すことができるのでしょうか?
なんとなくでしか理解できていないので、詳しい解説をお願いしたいです。

スタッフ

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

プレミアムプランとは?