I'm writing two scripts in an web environment where I don't have control over the order in which they are loaded. Let's say the two scripts are called MyUtil and DoSomething.
MyUtil contains utilities that I will bind to the window object using window.myUtil = myUtil. I'm then going to call methods of myUtil from within DoSomething.
If MyUtil is loaded first, everything will work. If it's loaded second, window.myUtil will be undefined.
How can I modify the code in DoSomething (and/or MyUtil) to wait until window.myUtil exists before DoSomething executes its code?
NB: I'm using jQuery 1.2.3.
MyUtil? If so, you can usejQuery.getScript()to load it and then callDoSomethingin the success callback.