JSFiddle - React, Tailwind, and code Playground

by doug65536

HTML

<button id="A">A</button>
<button id="B">B</button>
<button id="C">C</button>

JavaScript

function makeHandlerClosure(x, y, z) {
    // do stuff here, perhaps more variables, etc
    // this runs the moment the callback is being attached
    return function(event) {
        $('body').append('<br>' + 'x: ' + x + ' y:' + y + ' z:' + z);
    }
}

$('#A').on('click', makeHandlerClosure(1, 2, 3));
$('#B').on('click', makeHandlerClosure(4, 5, 6));
$('#C').on('click', makeHandlerClosure(7, 8, 9));