json内部のthis


JSONでのthis


json内部でこの内容を撮影すると、実行時にこの値が出力されます.
const json = {
	t: this
}

console.log(json);
// {t: Window}

JSONで自身を呼び出します。

  • から、関数をコンストラクション関数としてオブジェクト
  • を作成する.
    
    const json = new function() {
      this.a = "HI";
      this.b = " ";
      this.c = "THERE!";
      this.total = this.a + this.b + this.c;
    };
    
    console.log(json);
    // {a: "HI", b: " ", c: "THERE!", total: "HI THERE!"}