6. 노드에서의 this

console.log(this); // {}
// 노드에서 실행하는 자바스크립트는 특이한게 위와 같이 전역 this를 찍으면 빈 객체가 나온다.
// 브라우저에서 this는 window를 가리키기 때문에
// 노드에서도 global 객체가 나올거라 예상하지만, 아니다.

console.log(this === module.exports); // true
// 전역 스코프의 this가 빈 객체가 나오는 이유가 module.exports를 가리키기 때문이다.
console.log(this === exports); // true

function a() {
    // console.log(this); // <ref *1> Object [global] {...}
    console.log(this === global); // true
}
a();

// 위와 같은 경우 외엔 this 동작이 브라우저의 this 동작과 일치한다.
// 여튼 이런 특성을 사용하면
// exports.odd = odd; 가 아니라
// this.odd = odd; 이렇게도 정의가 가능하다.
// this가 module.exports이자 exports이기 때문에 가능한 것이다.

// 하지만 위와 같이 하면 헷갈려서 저렇게 안쓴다.