document.createElement ('сценарий') … добавление двух сценариев с одним обратным вызовом

При хранении объектов polymporhic, всегда необходимо использовать набор указателей базового класса.

Это - то, если Вы планируете хранение различных производных типов в Вашем наборе, необходимо сохранить указатели или есться разрезанием deamon.

10
задан Rob W 27 December 2011 в 22:23
поделиться

2 ответа

I propose you to use some small loader which will chain and do stuff for you. For example like this one:

function loadScripts(array,callback){
    var loader = function(src,handler){
        var script = document.createElement("script");
        script.src = src;
        script.onload = script.onreadystatechange = function(){
            script.onreadystatechange = script.onload = null;
            handler();
        }
        var head = document.getElementsByTagName("head")[0];
        (head || document.body).appendChild( script );
    };
    (function run(){
        if(array.length!=0){
            loader(array.shift(), run);
        }else{
            callback && callback();
        }
    })();
}

This script should help you to build the script tags and call your callback when all files are loaded. Invoke is pretty easy:

loadScripts([
   "http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js",
   "http://ajax.googleapis.com/ajax/libs/prototype/1.6.1.0/prototype.js"
],function(){
    alert('All things are loaded');
});

Hope this will help

39
ответ дан 3 December 2019 в 13:44
поделиться

Since scriptaculous requires prototype, you will have to chain the listeners, with whatever method you use to load these scripts.

There are various script loaders available to load scripts in parallel, as fast as possible, e.g. LABjs, but none is going to help much in this scenario.

If you end up having 10-20 scripts to load, I would recommend combining the scripts beforehand, using a tool such as a Combiner.

1
ответ дан 3 December 2019 в 13:44
поделиться
Другие вопросы по тегам:

Похожие вопросы: