curry 함수 만들어보기
No Filled
코드를 곱씹으면서 체화시키자. 🧐
function curry(fn) {
return function curried(...args) {
if (args.length >= fn.length) {
return fn.call(this, ...args)
}
return curried.bind(this, ...args)
}
}
this를 다루는 메서드들
매번 헷갈리는 부분인데 이번에 curry
함수를 만들어보면서도 this
를 다룰 때 시행착오를 겪었다.
다시 한 번 주요 특징들을 정리해두자..! 😇
apply
- 매개변수 배열로 전달 ex)
temp.apply(this, [1, 2 ,3])
- 함수 즉시 호출 ex)
temp.apply(this)
call
- 매개변수 각각 전달 ex)
temp.call(this, 1, 2 ,3)
- 함수 즉시 호출 ex)
temp.call(this)
bind
- 매개변수 각각 전달 ex)
temp.bind(this, 1, 2, 3)
- 함수 즉시 호출하지 않음 ex)
temp.bind(this)()