跳至主要內容
  • Hostloc 空間訪問刷分
  • 售賣場
  • 廣告位
  • 賣站?

4563博客

全新的繁體中文 WordPress 網站
  • 首頁
  • 作为 JavaScript 的一个内置函数,为什么 Proxy 没有 prototype 这个属性?
未分類
29 9 月 2020

作为 JavaScript 的一个内置函数,为什么 Proxy 没有 prototype 这个属性?

作为 JavaScript 的一个内置函数,为什么 Proxy 没有 prototype 这个属性?

資深大佬 : KyL 4

var proxy = new Proxy(target, handler);

console.log(Proxy.prototype);

Proxy 是一个方法,可是我在 Chrome 中尝试访问 Proxy.prototype 却为 undefined,在 node 中为 null 。Proxy 这个函数有什么特别之处?

大佬有話說 (2)

  • 資深大佬 : aaronlam

    首先构造方法的 prototype 不一定是为对象的呀,可以置为 null 的

    另外可以看下 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,再就是构造函数进行初始化。

  • 資深大佬 : xionger

    还没有用过

文章導覽

上一篇文章
下一篇文章

AD

其他操作

  • 登入
  • 訂閱網站內容的資訊提供
  • 訂閱留言的資訊提供
  • WordPress.org 台灣繁體中文

51la

4563博客

全新的繁體中文 WordPress 網站
返回頂端
本站採用 WordPress 建置 | 佈景主題採用 GretaThemes 所設計的 Memory
4563博客
  • Hostloc 空間訪問刷分
  • 售賣場
  • 廣告位
  • 賣站?
在這裡新增小工具