Skip to content

Instantly share code, notes, and snippets.

@athieriot
Created June 14, 2012 21:28
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 athieriot/2933064 to your computer and use it in GitHub Desktop.
Save athieriot/2933064 to your computer and use it in GitHub Desktop.
Trying to explain curryfication
#!/usr/bin/env node
//Declare curry method on every functions
Function.prototype.curry = function(arg1) {
//Keeping this just for later
var self = this;
//Keeping curried arg in the scope of the new function
var arg1 = arg1;
//Defining the new function which take one less parameter
return function(arg2) {
//Calling the original function with every parameters
self.call(self, arg1, arg2);
}
}
//One origin function taking to parameters and display them
var testFunction = function(un, deux) {
console.log(un + ' ' + deux);
}
//Indian spice
var testFunctionUn = testFunction.curry('un');
//That should display 'un - deux'
testFunctionUn('deux');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment