JSFiddle - React, Tailwind, and code Playground

by adriangonzy

HTML

<input type="button" id="my-belly" value="Test Currying" />

JavaScript

// Enter the curry !

var el = document.getElementById('my-belly');

function sayHelloAndCurryMe(msg, event) {
    alert(msg + ' \n You clicked on ' + this.id + ' \n Event Type: ' + event.type);
}

function curry (fn, scope) {
   
    scope = scope || window;
    
    // omit curry function first arguments fn and scope
    var curriedArgs = Array.prototype.slice.call(arguments, 2);
    
    return function() {
        // concat returned fonction arguments to curried arguments 
        var newArgs = Array.prototype.slice.call(arguments, 0);
        var trueArgs = curriedArgs.concat(newArgs);

        // call curried fonction with 
        fn.apply(scope, trueArgs);
    };
}

el.addEventListener('click', curry(sayHelloAndCurryMe, el, 'Hello Buddy !'));