gpt4 book ai didi

javascript - JS : Difference between Object and Object. 构造函数

转载 作者:行者123 更新时间:2023-12-03 01:41:43 25 4
gpt4 key购买 nike

我不明白 Object 和 Object.constructor 之间的区别。

让我们举个例子:

function Person() {}
var p = new Person();

Person是创建对象的函数。所以:

p instanceof Person //true
p.constructor // Person

Person 是构造函数,我可以使用 new Person() 创建人

但是 Object 也是一个构造函数(我可以使用 new Object() 创建对象)。既然 Object 本身就是一个构造函数,为什么它还要有一个构造函数属性呢?

谢谢

最佳答案

So why does it have a constructor property since it's already a constructor itself?

因为每个构造函数都是一个函数,并且它们从 Function.prototype 继承它们的属性(例如 callapplybind 方法)。 。包括指向 FunctionFunction.prototype.constructor 属性。

关于javascript - JS : Difference between Object and Object. 构造函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50817138/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com