this
-
Javascript에서의 thisProgramming/JavaScript & TypeScript 2022. 5. 24. 15:54
다음 코드에서 this는 gangwon객체가 아닌 다른걸 가르키게 된다. var gangwon = { resorts: ["Kirkwood","Squaw","Alpine","Heavenly","Northstar"], print: function(delay=1000) { setTimeout(function() { console.log(this.resorts.join(",")) }, delay) } } gangwon.print() 실제로 setTimeout안에서 this를 찍어보면 다음과 같은 결과를 보여준다. 따라서 this.resorts를 접근할 수 없는 것이다. 아래 소스를 보고 더 분석해보자 //node에서 this /* 함수 밖에서 this는 exports를 의미, 외부에게 제공하기 위한 내장객체를 ..