Skip to content

Instantly share code, notes, and snippets.

@awwright
Forked from ELLIOTTCABLE/Function..curry.js
Last active December 10, 2015 04:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save awwright/4378445 to your computer and use it in GitHub Desktop.
Save awwright/4378445 to your computer and use it in GitHub Desktop.
// Would prefer to use an actual Function-subclass a lá `from`, so that I don't have to manually
// attach a .toString() to each instance; but this will do for the moment.
// FIXME: Will currently error out if you curry in more arguments than the function needs
define(Function.prototype, 'curry', function(){
var self = this;
var result = new Function('bound', 'args',
"return this.apply("
+" typeof bound === 'object' || typeof bound === 'function'? bound:this"
+" , curried.concat([].slice.call(args)) )"
);
result.toString = self.toString.bind(this);
result.final = this.final || this;
return result.bind(this, arguments);
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment