Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在javascript中,为什么Array.constructor指向函数?_Javascript_Function_Constructor_Prototype - Fatal编程技术网

在javascript中,为什么Array.constructor指向函数?

在javascript中,为什么Array.constructor指向函数?,javascript,function,constructor,prototype,Javascript,Function,Constructor,Prototype,我目前正在研究javascript原型和继承,并提出了以下代码 > Array.constructor === Function; < true > Function.constructor === Function; < true >Array.constructor==函数; Function.constructor==函数; true ) console.log( Function.prototype.constructor===Function/=>true )

我目前正在研究javascript原型和继承,并提出了以下代码

> Array.constructor === Function;
< true
> Function.constructor === Function;
< true
>Array.constructor==函数;
Function.constructor==函数;

我无法理解为什么
数组。构造函数
指向
函数
以及为什么
函数。构造函数
指向
函数
?背后的原因是什么?javascript的创建者为什么要这样做?

数组
是一个函数-如果不是,你就无法编写
新数组()

因此,它的构造函数属性指向
函数

您可能正在寻找
Array.prototype.constructor
,它实际上是
Array
<另一方面,code>Function.prototype.constructor
与预期一样是
Function

构造函数的
原型
的属性是由您构造的任何实例继承的属性;例如
newarray().constructor==Array.prototype.constructor

静态属性(如
Array.constructor
)是从
函数.prototype
继承的,因为构造函数是函数,因此是
函数的实例

console.log(
Array.prototype.constructor===Array/=>true
)
console.log(
Function.prototype.constructor===Function/=>true

)
因为
数组
是一个函数,它的构造函数是
函数
<代码>函数
也是一个函数,其构造函数也是
函数
…所有构造函数的可能重复项都是函数。在所有的编程语言中,JavaScript、Java、C++、GO等都是如此。我认为解释<代码>数组、构造器< /C>和<代码>数组.java。请随意给我其他建议。我还添加了一个潜在的副本;这个问题以前有人问过。