Have you ever written a function that looks like this?
function requestProductDetails(id, k) { var value = gProductDetailsCache[id]; if (value) k(value) else ajax.get(‘/product/’+id, function(data) { gProductDetailsCache[id] = data; k(data); }); }
requestProductDetails calls its callback with the product details, which are stored in a cache. Since it might need to request this information from the server, it has to “return” it by passing it to a callback; in order to present a uniform API whether or not the product is cached, it “returns” the data this way whether it came from the cache or not. read more »