Report abuse

Code

1
2
3
4
5
6
7
8
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

1
2
3
function xy(x, y) { return x+y; }
var x = xy.curry(7);
x(3);     // 10