Skip to content

Instantly share code, notes, and snippets.

@fermion
Forked from gf3/gist:132012
Created July 14, 2010 18:36
Show Gist options
  • Save fermion/475816 to your computer and use it in GitHub Desktop.
Save fermion/475816 to your computer and use it in GitHub Desktop.
// Code
Function.prototype.curry = function() {
var func = this, a = Array.prototype.slice.call(arguments, 0);
return function() {
var a_len = a.length, length = arguments.length;
while (length--) a[a_len + length] = arguments[length];
return func.apply(this, a);
}
};
// Example 01
function xy(x, y) { return x+y; }
var x = xy.curry(7);
x(3); // 10
// Example 02
var warn = alert.curry("Warning!");
warn();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment