因为您似乎在问“为了便于阅读,我应该怎样称呼这个函数?” 验证“这是什么类型/分类的功能?”,我会投入两分钱:
remixInputMethod()
实际上,这只是重新连接函数用户与程序交互的方式的问题。我想像这样的东西在你想要与它交互的程序中会很有用,方法是传入不同于你希望用户与之交互的方式的输入。
this.sum = function(a,b){ return a+b; };
remixInputMethod = function(fn){
return function(arr){
return fn.apply(fn,arr);
};
};
var _sum = remixInputMethod(this.sum);
// Throughout your program, do some more advanced, funky stuff
var sums = (function buildListOfSums(num){
var arr = [], output = 0;
while(num--){
arr.push(num);
}
while(arr.length > 2){
output += _sum([arr[arr.length - 1], arr[arr.length - 2]]);
arr.pop(arr[arr.length - 1]);
arr.pop(arr[arr.length - 2]);
}
return output;
}(20));
console.log(sums);
// But for the user, lets say, who downloaded your API on Github and is using it to
// build their first webpage for their uncle
// who thinks they are smarter than bill gates
sum(1,2);