Permalink
Browse files

Adding an example of using proxy functions locally.

  • Loading branch information...
1 parent 0bd77b3 commit cf077836c053a43a27bcc9cedbbb250ec520bb05 @domenic domenic committed Jan 18, 2012
Showing with 24 additions and 0 deletions.
  1. +24 −0 README.md
View
@@ -415,6 +415,30 @@ If the promise is a proxy for a remote object, you can shave
round-trips by using these functions instead of ``then``. To take
advantage of promises for remote objects, check out [Q-Comm][].
+Even in the case of non-remote objects, these methods can be used as
+shorthand for particularly-simple value handlers. For example, you
+can replace
+
+```javascript
+return Q.call(function () {
+ return [{ foo: "bar" }, { foo: "baz" }];
+})
+.then(function (value) {
+ return value[0].foo;
+})
+```
+
+with
+
+```javascript
+return Q.call(function () {
+ return [{ foo: "bar" }, { foo: "baz" }];
+})
+.get(0)
+.get("foo")
+```
+
+
[Q-Comm]: https://github.com/kriskowal/q-comm

0 comments on commit cf07783

Please sign in to comment.