function eq (y) { return function forX(x) { return x === y } } function mod (y) { return function forX (x) { return x % y } } function compose (fn2, fn1) { return function composed (val) { return fn2(fn1(val)) } } function not (fn) { return function negated (...args) { return !fn(...args) } } isOdd = compose( eq(1), mod(2) ) isEven = not(isOdd) let fiveIsOdd = isOdd(5) let fourIsEven = isEven(4) console.log(`5 is odd ${fiveIsOdd}`) console.log('4 is even', fourIsEven)
来源:https://www.cnblogs.com/byxxw/p/11323581.html