JS - json 내부에서의 this

균비·2021년 2월 12일
0

javascript

목록 보기
2/2

JSON에서의 this

json 내부에서 this를 찍으면 실행환경상의 this 값이 출력됨

const json = {
	t: this
}

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

JSON에서 자신 자체를 호출하는 방법

  1. 처음부터 함수를 constructor로 만들어서 object 생성하기

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!"}
profile
뒹굴뒹굴 고3 개발자!

0개의 댓글