Promise as a proxy

One marvelous thing about a promise that distinguishes it from the rest is that it can act as a proxy for another object, not only for local objects but also for a remote object. There are methods that let you confidently employ properties or call functions. All of these exchanges return promises, so that they can be chained.

Here is list of functions you can use as proxies of a promise:

Direct manipulation

Using a promise as a proxy

value.foo

promise.get("foo")

value.foo = value

promise.put("foo", value)

delete value.foo

promise.del("foo")

value.foo(...args)

promise.post("foo", [args])

value.foo(...args)

promise.invoke("foo", ...args)

value(...args)

promise.fapply([args])

value(...args) ...

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.