curry - functional javascript

curry function test

Function.prototype.curry = function() {    var fn = this, args = Array.prototype.slice.call(arguments);    // alert(fn);    // function slice() { native code }    // alert(args);    // 2    return function() {        // alert(this); // ['t', 'e', 's', 't']        // alert(args.concat(Array.prototype.slice.call(arguments)));        return fn.apply(this, args.concat(Array.prototype.slice.call(arguments)));    };};var arr = 'test'.split('');Array.prototype.yaslice = Array.prototype.slice.curry(2);alert(arr.yaslice(3));// arr.slice(2,3) => 's'

References

  1. http://ejohn.org/blog/partial-functions-in-javascript/
  2. http://osteele.com/sources/javascript/functional/