这是在使用闭包的Javascript中有趣和实用的curring用法:
function converter(toUnit, factor, offset, input) { offset = offset || 0; return [((offset + input) * factor).toFixed(2), toUnit].join(" ");}var milesToKm = converter.curry('km', 1.60936, undefined);var poundsToKg = converter.curry('kg', 0.45460, undefined);var farenheitToCelsius = converter.curry('degrees C', 0.5556, -32);milesToKm(10); // returns "16.09 km"poundsToKg(2.5); // returns "1.14 kg"farenheitToCelsius(98); // returns "36.67 degrees C"这依赖于的curry扩展Function,尽管您可以看到它仅使用apply(没什么花哨的):
Function.prototype.curry = function() { if (arguments.length < 1) { return this; //nothing to curry with - return function } var __method = this; var args = toArray(arguments); return function() { return __method.apply(this, args.concat([].slice.apply(null, arguments))); }}


