ES6 proxies can't be functions?

2019-08-12 03:04发布

问题:

Does that document means that future javascript proxy implementations would not have Proxy.createFunction and I will not be able to create a proxy which could be called as a function?

http://people.mozilla.org/~jorendorff/es6-draft.html#sec-reflect-object

The Reflect object is a single ordinary object.

The value of the [[Prototype]] internal slot of the Reflect object is the standard built-in Object prototype object (19.1.3).

The Reflect object is not a function object. It does not have a [[Construct]] internal method; it is not possible to use the Reflect object as a constructor with the new operator. The Reflect object also does not have a [[Call]] internal method; it is not possible to invoke the Reflect object as a function.

回答1:

You are citing parts of the spec about the Reflect object, which mean nothing for proxies.

The ES6 described in the page you linked does still have Proxies. These objects can be [[call]]able (and even [[construct]]able). You're right that there is no Proxy.createFunction, all proxies seem to be uniformely created via new Proxy. You would need to pass a callable object (i.e. a function) as the ProxyHandler for creating a callable proxy object.