함수를 인자로 받거나 결과로 반환하는 함수
const func = () => {
return () => {
console.log('hello');
}
}
const innerFunc = func();
innerFunc(); // hello
이해가 어렵다면, func() 부분을 반환한 값으로 대체해 보자.
const innerFunc = () => {
console.log('hello')';
};
innerFunc(); // hello
const innerFunc = (msg) => {
console.log(msg);
};
innerFunc(); // hello
const innerFunc1 = func('hello');
const innerFunc2 = func('javascript');
const innerFunc3 = func();
innerFunc1(); // hello
innerFunc2(); // javascript
innerFunc3(); // undefined
대체를 해 보자.
const innerFunc1 = () => {
console.log('hello');
};
const innerFunc2 = () => {
console.log('javascript');
}
const innerFunc3 = () => {
console.log(); // 빈 값은 undefined
}
함수가 중복되면 고차 함수
를 사용하면 된다.