let multiply = function (x, y) { return x * y; }
let multiply2 = (x, y) => { return x * y; }
let multiply3 = (x, y) => (x * y);
let multiply4 = (x, y) => x * y;
this는 현재의 실행 컨텍스트이다. 풀어서 말하면 this는 함수를 호출할 때 함수가 어떻게 호출되었는지에 따라 바인딩되는 객체가 달라지는 객체다.
new
연산자로 생성된 function scope의 this) : 새로 생성된 객체
5. call, apply 호출 : call, apply의 첫 번째 인자로 명시된 객체
function Box(w, h) {
this.width = w;
this.height = h;
this.getArea = function () {
return this.width * this.height;
}
this.print = function () {
console.log(this.getArea());
}
}
let b = new Box(100, 50);
b.print();
// setTimeout(b.print, 1000); // TypeError
setTimeout(b.print.bind(b), 1000);