특정 함수에 특정 arguments를 도입하고 싶을 때 사용한다
1. call
: Function.prototype.call(thisArg, arg1, arg2, ...)
function makeParamsToArray() {
return Array.prototype.slice.call(arguments);
}
console.log(makeParamsToArray('first', 'second'))
//["first", "second"]
2. apply
: Function.prototype.apply(thisArg, [argsArray])
var min = Math.min(7, 35, 2, 8, 21);
console.log(min); //2
var arr = [7, 35, 2, 8, 21];
var min2 = Math.min.apply(null, arr);
console.log(min2); //2
3. bind
인자로 넘겨준 객체와 연결(bind)된 새로운 함수를 반환
callback 함수를 특정 객체와 연결하고 싶을 때 사용
//fn.bind(thisArg\[, arg1\[, arg2\[, ...\]\]\])
function foo(){
return this;
}
var boundFoo = foo.bind({a:1});
foo(); //Window
boundFoo(); // {a:1}
Asynchronous Call - Javascript (0) | 2019.04.16 |
---|---|
Prototype 프로토타입 - Javascript (0) | 2019.04.16 |
this의 적용 (0) | 2019.04.15 |
Closure Module Pattern (0) | 2019.04.15 |
Array Methods of Javascript (0) | 2019.04.15 |
댓글 영역