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
29
// variable
var increase = function (num) {
return ++num;
};
// variable
var decrease = function (num) {
return --num;
};
var predicates = { increase, decrease };
// makeCounter() => 고차함수
function makeCounter(predicate) { // parameter
var num = 0;
return function () { // anonymous
num = predicate(num);
return num; // return value
};
}
var increaser = makeCounter(predicates.increase);
console.log(increaser()); // 1
console.log(increaser()); // 2
var decreaser = makeCounter(predicates.decrease);
console.log(decreaser()); // -1
console.log(decreaser()); // -2
https://bestalign.github.io/dev/first-class-object/
https://poiemaweb.com/js-function#3-first-class-object-%EC%9D%BC%EA%B8%89-%EA%B0%9D%EC%B2%B4
https://poiemaweb.com/js-array-higher-order-function