//어떤 코드도 없는 경우
<초기화 하는 것들>
this : window
변수들(Variable Object) : {}
Scope chain : []
function myFunc() {
let a = 10
let b = 20
function add(first, second) {
return first + second
}
return add(a, b)
}
특정 함수가 존재하고 실행되는 경우
this : undefined
변수들 : {
first : 10
second : 20
}
Scope chain : [myFunc, global]
this : undefined(strict mode)
변수들 : {
a : 10
b : 20
add function {...}
}
Scope chain : [global]
this : window
변수들 : {}
Scope chain : []
쌓인 느낌? call stack
객체가 있고 객체의 메소드를 호출하는 상황
let o = {
name: 'Daniel',
method: function(number) {
return this.name.repeat(number)
}
}
function myFunc() {
let n = 10
return o.method(n)
}
myFunc()