Below is the code I am using in a project with some complex dependencies. After I have made sure that all the dependencies have been loaded I fire the onReadyCallback() also given below. I have two questions :
- Is it correct to use, anonymousHandler.apply(MyNameSpace), the apply method on an anonymous Handler being called for Document.ready
-
From what I understand, because I am using the apply method the anonymous function will fire immediately irregardless of document’s ready state. Then how can I pass in the context of MyNameSpace to the anonymousHandler so that “this” inside the function refers to MyNameSpace
var onReadyCallback = function(){ jQuery(document).ready(function(){ if(!this.loggedIn()){ return; } ...Lots of Code referring to MyNameSpace using "this" }.apply(MyNameSpace)); }; //load the additional files that are needed and fire onReadyCallback MyNameSpace.Util.loadFiles(defaultJsFiles,function(){ MyNameSpace.Util.require(['My.App','My.Theme','My.DomHandler'], function(){ onReadyCallback.apply(window); }); });
How about this, using an anonymous function and
call?