Intro
Do you know Async.js? It is a javascript framework helping deal with async functions. Let's imagine we want to render some html template:compare_two_items_html = function(item_1, item_2) {
return _.template("item #<%= item_1.id %>: <%= item_1.price %> USD vs. item #<%= item_2.id %>: <%= item_2.price %> USD");
}
And we have function of loading item:
load_item = function(id, callback) {
$.getJSON("/items/" + id, callback);
};
To render this, we should write something like that:
load_item(5, function(item_1) {
load_item(12, function(item_2) {
$("#compare_items").html(compare_two_items_html(item_1, item_2));
});
});
A little bit messy. Imagine if we had more then 2 dependencies.