gpt4 book ai didi

javascript - 构造函数总是函数对象吗?

转载 作者:数据小太阳 更新时间:2023-10-29 05:16:29 25 4
gpt4 key购买 nike

我正在阅读最新的 ECMA-262 引用,2011 年 6 月 5.1 版。

8.6.2部分关于 [[Construct]] 内部属性的表 9:

Creates an object. Invoked via the new operator. The arguments to the SpecOp are the arguments passed to the new operator. Objects that implement this internal method are called constructors.

标准并未规定构造函数必须是 Function 对象。那么我们可以拥有一个不是函数对象的构造函数对象吗?

Link to the standard as requested

最佳答案

答案非常简单。 ES5 § 4.3.4说:

构造函数 创建和初始化对象的函数对象。

好了,根据定义,只有 Function 可以是构造函数。但是,可能存在行为类似于构造函数的主机对象,它们不具有 native Function 对象的任何其他属性(例如,在 ActiveX 中实现的 IE 中的原始 XMLHttpRequest 对象)。

关于javascript - 构造函数总是函数对象吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10393858/

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