Avoiding eval you may try an approach based on accessing functions via some container (window for example):
const fnContainer = window;
$('#dgok').click(function(){
const fn = $(this).attr('data-fn');
const fnName = fn.substring(0, fn.indexOf('(')); // 'delbanner'
const fnArg = fn.substring(fn.indexOf('(') + 2, fn.length - 2); // 'banners'
if (typeof fnContainer[fnName] === 'function') {
fnContainer[fnName].apply(fnContainer, [fnArg]); // window[fnName](fnArg);
}
});
Here I assume that your function is defined on window and has 1 string argument.
Having function argument in a separate data-attribute the approach may look a bit simplier
const fnContainer = window;
$('#dgok').click(function(){
const fnName = $(this).attr('data-fn');
const fnArg = $(this).attr('data-arg');
if (typeof fnContainer[fnName] === 'function') {
fnContainer[fnName].apply(fnContainer, [fnArg]); // window[fnName](fnArg);
}
});
bannersis an argument of the function.eval, but it's not a great idea. Why do you need to pass functions around indata-attributes?