var proxy = new Proxy(target, handler);
console.log(Proxy.prototype);
Proxy 是一个方法,可是我在 Chrome 中尝试访问 Proxy.prototype 却为 undefined,在 node 中为 null 。Proxy 这个函数有什么特别之处?
首先构造方法的 prototype 不一定是为对象的呀,可以置为 null 的
另外可以看下 ECMA 对于 Proxy 构造函数的规范:
http://www.ecma-international.org/ecma-262/Properties of the Proxy Constructor
·has a [[Prototype]] internal slot whose value is %Function.prototype%.
·does not have a "prototype" property because proxy exotic objects do not have a [[Prototype]]
internal slot that requires initialization.
由于 Proxy 构造出来的实例对象是对 target 的一个代理,所以 Proxy 在构造过程中是不需要 prototype 进行初始化的。
另外我记得正常的构造函数在 new 运算的时候,是首先会取构造函数的 prototype 去构建一个实例,然后再传入构造函数内充当 this,再就是构造函数进行初始化。
还没有用过
对象基本由数据和功能两部分组成,在构造函数创建对象的过程中,构造函数本身的过程实际上是在构造对象的数据部分,而 prototype 其实相当于对象的功能部分,而 Proxy 构造函数产生的对象所具备的功能并不来自于 Proxy 类自己所定义的功能,而是开发者想代理的对象的功能,所以对于 Proxy 来说,没必要存在它自己的 prototype 。