Permalink
Browse files

clarified docs to always use 'new' to create a proxy, in light of for…

…ward-compat with ES6
  • Loading branch information...
1 parent 0d3cd6d commit 02a24fcaf29fa939a75e6684c6d99f4f9bd11d06 @tvcutsem committed Jan 9, 2014
Showing with 8 additions and 6 deletions.
  1. +1 −1 README.md
  2. +4 −2 doc/api.md
  3. +2 −2 doc/handler_api.md
  4. +1 −1 doc/traps.md
View
@@ -8,7 +8,7 @@ a global object `Reflect` is defined that contains the functions from the [ES6](
The `Proxy` object is also updated to follow the latest [direct proxies](http://wiki.ecmascript.org/doku.php?id=harmony:direct_proxies) [spec](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-proxy-factory-function). To create such a proxy, call:
- var proxy = Proxy(target, handler)
+ var proxy = new Proxy(target, handler)
If you are using node.js (>= v0.7.8), you can install via [npm](http://npmjs.org):
View
@@ -8,7 +8,9 @@ Creates and returns a new proxy object. The `handler` object may define [trap fu
Both target and handler must be non-null objects.
-Note: In the ES6 API, `Proxy` will be a constructor function that will _require_ the use of `new`. That is, you must write `new Proxy(target, handler)` to construct a proxy object. This library exports `Proxy` as an ordinary function which may be called with or without the `new` operator.
+Note: In the official ES6 API, `Proxy` will be a constructor function that
+will _require_ the use of `new`. That is, you must write `new Proxy(target, handler)` to construct a proxy object. This library exports `Proxy` as an ordinary function which may be called with or without the `new` operator.
+For forward-compatibility, it is advised to always use `new`.
## Proxy.revocable(target, handler)
@@ -175,7 +177,7 @@ The intent is for users to "subclass" `Handler` and override the "fundamental" t
MyHandler.prototype.defineProperty = function(tgt,name,desc) {...};
// create a proxy with an instance of the Handler "subclass"
- var proxy = Proxy(target, new MyHandler());
+ var proxy = new Proxy(target, new MyHandler());
// MyHandler's inherited "set" trap will call the overridden "defineProperty" trap
proxy.foo = 42;
View
@@ -4,7 +4,7 @@ This API documents all the functions that a proxy handler object may implement t
As an example, the below proxy logs all `get` and `set` operations applied to it, then forwards the operations to its target object:
- var proxy = Proxy({}, {
+ var proxy = new Proxy({}, {
// intercepts proxy[name]
get: function(target, name, receiver) {
console.log('get',name);
@@ -115,7 +115,7 @@ Examples:
}
}
};
- var proxy = Proxy(target, handler);
+ var proxy = new Proxy(target, handler);
Object.getOwnPropertyDescriptor(proxy, "x")
// calls handler.getOwnPropertyDescriptor(target, "x")
// returns {value: 0, writable: true, configurable: true, enumerable: true}
View
@@ -212,7 +212,7 @@ try {
* (1): in Javascript, a method call like `obj.foo(1,2,3)` is defined as looking up the "foo" property on `obj`, and then calling the resulting function with `obj` as the `this`-binding. If `obj` is a proxy, the same strategy applies. There is no separate `invoke` trap.
* (2): the `for-of` statement is forthcoming in ECMAScript 6.
* (3): the syntax `...args` is ECMAScript 6 syntax for "spreading" arguments into a call. `f(...[1,2,3])` is equivalent to `f(1,2,3)`. Function calls can only be intercepted if the target is a function, i.e. `typeof target === "function"`.
- * (4): this assumes that the proxy was installed as a method on `object`, e.g. `var object = { proxy: Proxy(target, handler) }`.
+ * (4): this assumes that the proxy was installed as a method on `object`, e.g. `var object = { proxy: new Proxy(target, handler) }`.
* (5): assuming that `proxy.call`, which triggers the proxy's "get" trap, returned `Function.prototype.call`.
* (6): assuming that `proxy.hasOwnProperty`, which triggers the proxy's "get" trap, returned `Object.prototype.hasOwnProperty`.
* (7): assuming that `proxy.valueOf`, which triggers the proxy's "get" trap, returned `Object.prototype.valueOf`.

0 comments on commit 02a24fc

Please sign in to comment.