The below script is trying to test the existence of lets say Utility.Method.PageInit();
the page object comes in dynamically, as does the event parameter, so I don’t actually know what they will be, so I need to test the existence of a dynamic function (if you understand me correctly).
var key = page.attr('id');
var funcToCall = key + '.Method.' + event;
//check if function exists, if it doesn't return, (guard statement)
if (typeof (eval(funcToCall)) != 'function') { return; }
Problem is, the eval is actually calling it, and then its throwing an error “function doesn’t exist blahblah”.
How can I test the existence of it without getting an error?
Ah I’ve figured it out, didn’t realize how easy was, because its a function inside an object, inside an object you need to test from the top level down progressively, so: