Function and function difference unCurry curry:
curry function of: a fixed part of the parameters, receiving a new function returns the remaining parameters, the purpose of narrowing the scope of application, create a more targeted function.
unCurry of function: broaden the scope of a function to create a wider range of applications. Originally, only the method applies a specific object, and expand to more objects.
unCurry Function Reference: https://www.cnblogs.com/pigtail/p/3450852.html https://juejin.im/post/5b561426518825195f499772#heading-7
方法一:
class Toast{ constructor(){ this.prompt='' } show(){ console.log(this.prompt); } } var temObj={prompt:'tem'} Toast.prototype.show.call(temObj) function unCurry(fn){ return function(context){ var args=Array.prototype.slice(1)||[]; fn.apply(context,args) } } var unCurryShow=unCurry(Toast.prototype.show); unCurryShow(temObj)
方法2 Function.prototype.unCurrying = function(){ var self = this; return function(){ return Function.prototype.call.apply(self, arguments); } //return this.call.bind(this); } // 使用 var objShow = Toast.prototype.show.unCurrying(); objShow(obj);
application:
Function.prototype.unCurry=function(){ return this.call.bind(this) } var objPush=Array.prototype.push.unCurry(); var temObj={}; objPush(temObj,'a','b')
![](https://img2018.cnblogs.com/blog/1120691/201907/1120691-20190702210611017-541761453.png)
var toUpperCase = String.prototype.toUpperCase.unCurrying(); console.log(toUpperCase('avd')); // AVD function AryUpper(ary) { return ary.map(toUpperCase); } console.log(AryUpper(['a', 'b', 'c'])); // ["A", "B", "C"]
var call = Function.prototype.call.unCurrying(); function $(id) { return this.getElementById(id); } var demo = call($, document, 'demo'); console.log(demo); //Function.prototype.call.call(fn,context,...args)
var objToString=Object.prototype.toString.unCurry() var fn1=function(){} objToString(objToString)