Skip to content

Instantly share code, notes, and snippets.

@athieriot
Created June 14, 2012 21:28

Revisions

  1. athieriot created this gist Jun 14, 2012.
    28 changes: 28 additions & 0 deletions Curry.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    #!/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');