티스토리 뷰

반응형
  • 함수에 대해 호출된 bind()는 인자로 this를 전달한다.
function temp () {
    return this.x;
}

console.log(temp());
console.log(
    temp.bind({ x: 42 })()
);

/* 실행 결과
undefined
42
*/
  • bind() 의 두 번째 인자부터는 binding 대상 함수의 인수로 전달된다.
function temp (prop) {
    return this[prop];
}

console.log(temp('x'));
console.log(
    temp.bind({ x: 42 }, 'x')()
);

/* 실행 결과
undefined
42
*/
댓글
반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/02   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28
글 보관함