JSFiddle - React, Tailwind, and code Playground
by darul75
HTML
<div id="script"></div>
JavaScript
// take a filename, and a callback
function getScript(name, cb) {
var time = Math.random() * 5000;
setTimeout(
function() {
cb(null, '\n source for library '+name);
},
time
);
}
function loadScript(scripts, callback) {
var data = [];
var l = scripts.length;
for (var i=0;i<scripts.length;i++) {
getScript(scripts[i], function(source) {
data[i] = source; // i will always be the same..
// below condition never verified
if (data.length === l) {
callback(data.join(''));
}
});
}
}
var libs = ['jquery', 'backbone', 'lodash'];
loadScript(libs, function(data) {
console.log('end callback : ' + data);
var p = document.createElement(p);
p.innerHTML = data;
document.getElementById("script").appendChild(p);
});