목록2021/06/28 (2)
Jiyong's STUDY
this는 객체를 가리키는 포인터와 같은 존재라고 볼 수 있다. 기본적으로 this가 가리키고 있는 것은 전체를 가리키고 있는데, 브라우저의 경우 window를, node.js의 경우에는 global을 가리킨다. 객체 안에서 this를 사용하면 다음과 같이 사용된다. const a = { foo: 'foo', bar: 'bar', f1: function() { return this.foo; }, f2: function() { return this.bar; }, f3: function () { return this; } } console.log(a.f1()); console.log(a.f2()); console.log(a.f3()); -- node test.js foo bar { foo: 'foo', ba..
test1(); function test1() { console.log('test1'); } -- node test.js test1 -- test1의 선언보다 호출을 먼저 했지만 정상적으로 실행이 된다. test2(); var test2 = function() { console.log('test2'); } -- node test.js /Users/jiyong/WebstormProjects/study-types/test.js:6 test2(); ^ TypeError: test2 is not a function -- 마찬가지로 선언보다 호출을 먼저 했지만 오류가 난다. 두 개의 차이는 일반 함수와 인라인 함수에서 나는 차이긴 하지만, 아무튼 호이스팅이 적용된 결과라고 볼 수 있다. test2(); let t..