javascript - How to delay executing of called function? -
i'm making api application, using modules. place each module in corresponding .js file, , after push .js's in page head:
app.loadmodule = function (src) { var script = document.createelement('script'); var appendto = document.getelementsbytagname('head')[0]; script.src = app.prefs.domain + '/js/mods/' + src + '.js'; appendto.appendchild(script); }; app.printloadedmodule = function (name) { console.log(name + '.js'); }; app.moduleloader = (function () { var modules = app.modulestoload; (var = 0, len = modules.length; < len; i++) { app.loadmodule(modules[i], app.init); } })();
after client can call api functions situated in modules. so, calls must executed after scripts appear in head.
i have:
app.init = function() { if (app.isfunc(callback)) { callback(); } };
the client calls api this:
app.init(function () { app.api('user.get', {user_ids: '1'}, function (data) { console.log(data); }); });
the problem don't understand how delay executing client calls until app.moduleloader has finished.
thanks in advance!
Comments
Post a Comment