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)