在前面两个章节“Javascript之一切皆为对象1”和“Javascript之一切皆为对象2”中,曾提到:

1、“一切(引用类型)皆为对象”

2、 “每个函数都有一个prototype”

3、 “每个对象都有一个__proto__”

那么,问题来了,在随笔“Javascript之一切皆为对象2”中,不是有下图么

javascript之一切皆为对象3

那,根据“一切(引用类型)皆为对象”,图中的函数Fn不也是对象吗?

那它也有__proto__,那么它是指向谁的呢?!!

答案:Function.prototype

为什么这么说呢?

因为函数Fn不是通过Function创建的么

所以Fn.__proto__指向的是Function.prototype。

不信?

我们一起写个demo并运行代码,证实下。打开chrome调试器截图如下。

<!DOCTYPE html>
    <head>
        <title>ttt</title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    </head>
    <body>
        <script>
            //创建一个Fn函数
            function Fn(){}
            //打印Fn的隐指针,即Fn.__proto__
            console.log(Fn.__proto__);
        </script>
    </body>
</html>
View Code

相关文章:

  • 2021-08-18
  • 2022-12-23
  • 2021-05-24
  • 2021-08-17
  • 2021-07-06
猜你喜欢
  • 2021-11-22
  • 2021-12-16
  • 2022-12-23
  • 2022-12-23
  • 2021-09-08
相关资源
相似解决方案