I need a way to execute function that has parameters:
func1(param1, param2)
{...
}
when I get the function name and its parameters as parameters (or string variables) in another function:
parentFunc()
{
var funcName="func1";
var params = {'param1': 'A', 'param2': 'B'}
//Here I want to execute the funcName (func1) with its params.
}
I've tried creating customEvent, but the param didn't pass:
var event = new CustomEvent("func1", {
"param1": 'A', "param2": 'B'
});
this.element.dispatchEvent(event);//The element is the "parent"
//htmlElement that responsible to the
//event
*The functions are not in the same file and I'm doing in a Single Page Application (SPA), so doing it as shown below is not good enough:
var fn = window[settings.functionName];
Generally - what I'm trying to do is in a custom element - have the option to decide what function is executed (it is in the parent template) when there is event in the custom element