ES6代理不能功能? [英] ES6 proxies can't be functions?

查看:122
本文介绍了ES6代理不能功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

该文件是否意味着将来的JavaScript代理实现不会有 Proxy.createFunction ,我将无法创建一个可以被称为函数的代理? / p>

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



Reflect对象是一个普通的对象。



Reflect对象的[[Prototype]]内部插槽的值是标准的内置对象原型对象(19.1.3)。



Reflect对象不是函数对象。它没有[[Construct]]内部方法;使用新的运算符不能使用Reflect对象作为构造函数。 Reflect对象也没有[[Call]]内部方法;不可能调用Reflect对象作为一个函数。

解决方案

您正在引用有关反映对象,这对于代理来说意味着什么。



在您链接的页面中描述的ES6仍然具有代理这些对象可以是 [[call]] (甚至 [[construct]] )。你是对的,没有 Proxy.createFunction ,所有代理似乎都是通过 。您需要将 ProxyHandler 的可调用对象(即函数)传递给创建一个可调用的代理对象。


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.

解决方案

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.

这篇关于ES6代理不能功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆