Created
June 14, 2012 21:28
-
-
Save athieriot/2933064 to your computer and use it in GitHub Desktop.
Trying to explain curryfication
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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