View revisited
The view()
method helps in mirroring all the values into Q-based promises without any distinction, either it comes from a value or any other function. There are two methods that can make this possible:
promise.post(name)
promise.send(name)
This converts a method of the promise value to a promise of the method result.
A result of view()
has methods for all methods of the promise value. You can use view
in the then
callback of view()
, for example:
// object-view.js Q.resolve(new Date()).view().then(function (dateView) { return dateView.toTimeString().then(function (str) { return /\((.*)\)/.exec(str)[0] }); }).then(console.log);
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.