constisType=(type:string)=>(value:any)=>typeof(value)===type;什么?在理解双箭头函数之前,可以先了解一下函数式编程中的一个概念:currying:将多参数函数转换为嵌套一元函数(只有一个参数的函数)的过程。可以看出,双箭头函数是多参数函数的柯里化版本。转换为JavaScript后:constisType=function(type){returnfunction(value){returntypeof(value)===type;}}(看起来像一个闭包,也可以理解为把它们每一个封装在一个步骤中,保存每一步的结果,作为下一步开始的条件)你也可以不柯里化写一个函数:constisType=function(type,value){returntypeof(value)===类型;}调用方式:isType("string")//返回函数:function(value){returntypeOf(value)===type;}isType("string")("abc")//返回:trueconsttype=isType("字符串");输入(“abc”);//return:true为什么?那么问题来了,为什么要咖喱呢?这是为了什么?可读性:isType("string")("abc")可重用性:Reuseconsttype=isType("string");用于做其他判断类型("def");可维护性:constfn=(a,b)=>a*b;//可以修改为a+bconstisType=(fn)=>(type)=>(value)=>fn(type,value);console.log(isType(fn)(2));//返回函数console.log(isType(fn)(2)(3));//6consttype=isType(fn)(2);控制台日志(类型(4));//8如何?使用场景日志:constcurry=(fn)=>{if(typeoffn!='function'){throwError('NOfunctionprovided');返回f函数curriedFn(...args){if(args.length
