Equivalent of a class loader in Javascript
angularjs, javascript
Solution
RequireJS does exactly this by allowing you to define your dependencies and then only executing your code once the dependencies have loaded. If you are using something like the Google Maps API that loads in multiple dependencies of its own there is even a plugin that will wait for all of the third party dependencies to load as well.
There is a short write-up that shows you how to integrate AngularJS with RequireJS. As an added bonus, Require comes with an optimizer that you can run as part of your deployment build process to compile all of your local files into a single file.
Problem
In `Java` the class loader loads dynamically Java classes into the JVM. In `Javascript` I often have a problem of a call done on an unloaded dependency because the loading is done asynchronously. I use the `Angular JS` framework. For example one page depends on an API, but get an error `Cannot read property 'realestate' of undefined` when calling ``` gapi.client.realestate.get(propertyId).execute(function(resp) { console.log(resp); }); ``` because the API is not loaded. The loading is done by ``` loadRealEstateAPI = function() { var ROOT = 'http://localhost:8888/_ah/api'; gapi.client.load('realestate', 'v1', function() { console.log("Real Estate API loaded"); $rootScope.$broadcast("reAPILoaded", true); }, ROOT); } ``` I would like to know if there a JS library that let the application starts when all dependency are loaded.