노트 노드에서 this는 무엇일까요?
노드의 this는 브라우저의 this와 조금 다릅니다.
this.js
console.log(this);
console.log(this === module.exports);
console.log(this === exports);
function whatIsThis() {
console.log('function', this === exports, this === global);
}
whatIsThis();
콘솔
$ node this
{}
true
true
function false true
다른 부분은 브라우저의 자바스크립트와 동일하지만 최상위 스코프에 존재하는 this는 module.exports(또는 exports 객체)를 가리킵니다. 또한 함수 선언문 내부의 this는 2.5.1절에서 배울 global 객체를 가리킵니다.