JSFiddle - React, Tailwind, and code Playground
HTML
<button id="first">First</button>
<button id="second">Second</button>
JavaScript
function runOnce( callback ) {
var done = false;
return function() {
if ( !done ) {
done = true;
callback();
}
};
}
var one = runOnce(function() { alert('Once'); }),
two = runOnce(function() { alert('Once only too.'); });
document.getElementById('first').onclick = one;
document.getElementById('second').onclick = two;