JavaScript
- 7 ответов
- 0 вопросов
9
Вклад в тег
fetchUser().then(function(user){
return fetchUserPosts(user.id);
})
Q.spawn(function*(){
var user = yield fetchUser();
var userPosts = yield fetchUserPosts(user.id);
return userPosts;
});
function fetch(url,callback){
var req = new XMLHttpRequest();
req.open("GET",url);
req.onload = function(){
callback(req.responseText);
}
req.send();
}
function insertScript(scriptBody){
var script = document.createElement('script');
script.innerText = scriptBody;
document.body.appendChild(script);
}
var scripts = ["/first.js","second.js"];
var bodies = new Array(scripts.length);
scripts.forEach(function(script,index){
fetch(script,function(body){
bodies[index]=body;
if(bodies.every(function(el){return el})) {
bodies.forEach(insertScript);
}
});
})
angular.element(document.getElementById('foo')).append($compile("<h2 ev-click>add element</h2>")($scope));