Friday, 6 September 2013

How to check if a namespaced function exists?

How to check if a namespaced function exists?

Is there a way to find out if a function in a namespace exists? I'm trying
to get the attribute value of an HTML element and then checking if the
string value has a corresponding JavaScript function.
<a id="myLink" href="http://stackoverflow.com/"
data-success-callback="$.Namespace.SomeFunction" />
var successCallback = $('#myLink').data('success-callback');
I know I can use typeof window[callback] === 'function' to check for
functions declared globally but this doesn't seem to work with functions
in a namespace; it's undefined.
Is there a way to handle this?
Thank you :)

No comments:

Post a Comment