Now I have a module which follows a long chain of namespaces, for example:
TOP.middle.realModuleName = function () { /*...*/ }
I need to use this module on a page, and I’m not sure if this page has included the namespace Top.middle. So I would have to do something like:
if (typeof TOP !== 'undefined' && TOP.middle && TOP.middle.realdModuleName) {
new TOP.middle.realModuleName();
}
I think the if statement looks really long and verbose. Anyone has suggestions on how to write a nicer parameter checking pattern for this case?
just encapsulate it in a TRY/CATCH?