作为 JavaScript 的一个内置函数,为什么 Proxy 没有 prototype 这个属性?
資深大佬 : KyL 4
var proxy = new Proxy(target, handler);
console.log(Proxy.prototype);
Proxy 是一个方法,可是我在 Chrome 中尝试访问 Proxy.prototype 却为 undefined,在 node 中为 null 。Proxy 这个函数有什么特别之处?
大佬有話說 (2)
var proxy = new Proxy(target, handler);
console.log(Proxy.prototype);
Proxy 是一个方法,可是我在 Chrome 中尝试访问 Proxy.prototype 却为 undefined,在 node 中为 null 。Proxy 这个函数有什么特别之处?
另外可以看下 ECMA 对于 Proxy 构造函数的规范:
http://www.ecma-international.org/ecma-262/#sec-proxy-constructor
26.2.2 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,再就是构造函数进行初始化。