1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| function isType(type, value) { console.log(type, value, Object.prototype.toString.call(value)); return Object.prototype.toString.call(value) === `[object ${type}]`; }
function currying(fn, arr = []) { let len = fn.length;
return function (...args) { arr = [...arr, ...args]; if (arr.length < len) { return currying(fn, arr); } else { return fn(...arr); } } }
let isArray = currying(isType)('Array'); let isString = currying(isType)('String');
console.log(isArray([])); console.log(isString('111'));
|