问题描述:

I'm loading my javascript files asynchronously. I need to ensure that the order of loading is met. Here's my loading function:

 function addTag(name, attributes, cond) {

var el = document.createElement(name),

attrName;

for (attrName in attributes) {

el.setAttribute(attrName, attributes[attrName]);

}

if(cond != ''){

el = document.createComment('[if '+cond+']>'+outerHTML(el) + '<![endif]');

}

var headEl = document.getElementsByTagName('head')[0];

headEl.appendChild(el);

}

function outerHTML(node){

// if IE, Chrome take the internal method otherwise build one

return node.outerHTML || (

function(n){

var div = document.createElement('div'), h;

div.appendChild(n);

h = div.innerHTML;

div = null;

return h;

})(node);

}

I was thinking that a timeout function should be called but im not quite sure and also not quite sure about the interval time.

Any suggestions?

网友答案:
function callback(arg){
    //your stuffs
}
function main(arg, callback){
    //stuffs
    callback(arg);
}

Hope this helps.For more

相关阅读:
Top