Object handling promises

We learned a great deal about how promises help object handling whether these are local objects or remote ones. As mentioned earlier, the then callback can use the result in any way. Also, each handling is decomposed primitives of property accesses or function calls, for example:

// object-unsued.js
httpGet(url.parse("http://abc.org")).then(function (response) {
    return response.headers["location"].replace(/^http:/, "");
}).then(console.log);

Decomposition of primitive access

Q can decompose continuous actions of each primitive access. Let's have a look at the following code:

// object-decomposed.js httpGet(url.parse("http://abc.org")).then(function (response) { return response.headers; }).then(function (handlers) { return ...

Get Mastering JavaScript Promises now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.