SOURCE

function compose(...fns) {
    return function(...args) {
        let res = null
        let isFirstFn = true
        for(let fn of fns.reverse()) {
            if (isFirstFn) {
                isFirstFn = false
                res = fn.apply(this, args)
            } else {
                res = fn.call(this, res)
            }
        }
        return res
    }
}

function add(a, b) {
    return a + b
}
function mutil(a) {
    return a * 10
}
function minus(a) {
    return a - 1
}

let fn = compose(minus, mutil, add)
console.log(fn(2, 5))
console 命令行工具 X clear

                    
>
console