I know how to check to see if a property of the global context exists. Any variation of
if (typeof myFunction != 'undefined'){...}
but what if I don't know the name of the function? I think globally I could do this
if (typeof this['myFunction'] != 'undefined'){...}
but I don't know how to do that in a function like this
function load(functionName){
if (typeof GLOBALCONTEX[functionName] != 'undefined'){
GLOBALCONTEX[functionName](arg1 , arg2 , ...);
}
}
And I don't want to use try/catch as I have heard it is slow.
If working with a browser, substitute GLOBALCONTEX with window. Example:
function load(functionName){
if (typeof window[functionName] != 'undefined'){
window[functionName](arg1 , arg2 , ...);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With