js函数柯里化

    function curring(fn) {
        const inner = (args = []) => {
            return args.length >= fn.length ? fn(...args) : (...userArgs) => inner([...args,...userArgs]);
        }
        return inner();
    }
    function isType(typing, val) {
        return Object.prototype.toString.call(val) == `[object ${typing}]`;
    }
    let util = {};
    ['String', 'Number', 'Boolean', 'Null', 'Undefined'].forEach(type => {
        util['is'+ type] = curring(isType)(type)
    })
    console.log(util)

 

posted @ 2022-03-23 09:10  javascript9527  阅读(49)  评论(0编辑  收藏  举报