JSFiddle - React, Tailwind, and code Playground
HTML
<button class="call-method" data-method="One">Call methodOne()</button>
<button class="call-method" data-method="Two">Call methodTwo()</button>
JavaScript
var App = function() {
var that = this;
this.init = function() {
var elements = document.getElementsByClassName('call-method');
for(var i = 0; i < elements.length; i++) {
elements[i].addEventListener('click', function() {
that['method' + this.dataset.method](this);
});
}
};
this.methodOne = function(element) {
console.log(element.innerText);
};
this.methodTwo = function(element) {
console.log(element.innerText);
};
};
(function() {
var app = new App();
app.init();
}());