someFunction.Prototype.constructor vs someFunction.constructor [英] someFunction.Prototype.constructor vs someFunction.constructor

查看:114
本文介绍了someFunction.Prototype.constructor vs someFunction.constructor的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道JavaScript中的函数首先导致函数的双重生命(作为创建实例的第一类事物)和普通对象的第二个函数。

I am aware of the fact that functions in JavaScript lead a dual life first of a function (as first class thing to create instances from) and the second one of a normal object.

但我很惊讶看到以下控制台的输出。

But I am surprised to see the output of the following console.

function A() {
    console.info("A");
}
console.info(A.prototype.constructor === A.constructor); // false

我预计它是真的,因为我没想到构造函数对象的属性 A ,因为它是自己的属性。因此,在原型链查找之后,它应该是与 A.prototype.constructor 相同的对象。我错在哪里或者我错过了什么?

I expected it to be true as I was not expecting constructor property on the object A as it's own property. And hence following the prototypical chain lookup it should have been the same object as A.prototype.constructor. Where am I wrong or what piece am I missing?

推荐答案


我错在哪里或者是什么我错过了吗?

Where am I wrong or what piece am I missing?

A 不会从<$ c $继承C> A.prototype 。 A 是一个(构造函数)函数,并且继承自 Function.prototype 。做一个 console.log(Object.getPrototypeOf(A)): - )

That A does not inherit from A.prototype. A is a (constructor) function, and inherits from Function.prototype. Do a console.log(Object.getPrototypeOf(A)) :-)

来自 A.prototype 新的A 实例继承(其 .constructor A )。另请参见 __proto__ VS. JavaScript中的原型

From A.prototype only new A instances do inherit (whose .constructor is A). See also __proto__ VS. prototype in JavaScript.

这篇关于someFunction.Prototype.constructor vs someFunction.constructor的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆