起因:函数式编程的讨论,看到众多大佬讨论函数式编程的优劣。忽然想到自己最近看 axios 源码中的例子,在判断类型时用了柯里化的技巧。
const kindOf = (cache => thing => {
const str = toString.call(thing);
return cache[str] || (cache[str] = str.slice(8, -1).toLowerCase());
})(Object.create(null));
const kindOfTest = (type) => {
type = type.toLowerCase();
return (thing) => kindOf(thing) === type
}
const isDate = kindOfTest('Date');
想请问大家,这样的技巧有什么 具体 的作用呢?