I'm adding an onclick listener to the whole document then checking the source of the click. If the source of the click contains the attribute data-widget
I want to go to the appropriate action. I did it but I'm hoping for a more efficient way of doing things and if I can do without the self invoking function.
<div data-widget="myaction"> Click here </div>
document.addEventListener("click", function(e) {
var widgets = new Widgets();
var w = e.target.getAttribute("data-widget");
if(w){
e.preventDefault();
widgets[w];
}
});
function Widgets(){
var myaction = (function myaction(){
console.log('indeed');
})();
}
widgets[w]
line does nothing but access a member of that object. It doesn't appear to call a function. Is that the intent? \$\endgroup\$Widgets
constructor and not publically available using dot or array syntax. Invokingnew Widgets
is actually calling the "myaction" function. This is a bug since the "data-widget" attribute does not even need to exist to execute that function. \$\endgroup\$