在javascript中,我对回调函数进行了currying(因为它们在被调用后不能传递任何参数(来自调用者)
所以像:
...
var test = "something specifically set in this function";
onSuccess: this.returnCallback.curry(test).bind(this),
// This will fail (because this would pass the var and possibly change it should the function be run elsewhere
onSuccess: this.returnCallback.bind(this,test),
...
// this has 2 params, but in the ajax callback, only the 'ajaxResponse' is passed, so I have to use curry
returnCallback: function(thePassedVar, ajaxResponse){
// now in here i can have 'thePassedVar', if
}
我不确定这是否足够详细或连贯......但是currying基本上可以让你“预填充”参数并返回一个已经填充数据的裸函数调用(而不是要求你在其他点填充该信息)