构造函数创建的对象的 __proto__ 值是什么 [英] What is the __proto__ value of an object that is being created by constructor

查看:47
本文介绍了构造函数创建的对象的 __proto__ 值是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道在网络或书籍中似乎有很多关于我的问题的参考,但相信我,如果我问这意味着在阅读书籍/观看视频后我很困惑.所以请尽量不加评判地提供帮助:)我有以下代码:

I know that it seems that there is a lot of reference in the net or books for my question, but believe me that if i'm asking it's mean that after reading books/seeing videos i'm very confused. So please try to help without judging :) I have the following code:

  const Person = function (firstName, birthYear) {
  // Instance properties
  this.firstName = firstName;
  this.birthYear = birthYear;

我正在创建一个 Person 对象:

I'm creating an object of Person:

let p = new Person('Mike',35)

然后在将 p 打印到控制台时看到 proto 属性来自 Object 类型而不是 Person 类型.是我看错了还是我不懂原型理论?

Then when printing p to console is see that the proto property is from Object type and not a Person type. Am i reading it wrong or i don't understand the prototype theory?

我的小姐可能从我看到的讲座中感到困惑:

My miss confuse maybe from a lecture i saw:

推荐答案

__proto__ 在这种情况下指向 Person.prototype

__proto__ points to Person.prototype in this case

啊哈,我终于明白你在问什么了,你在用另一种有类型"的编程语言思考.你在 JS 中看到,函数是一个对象.没有课.您创建的每个对象都将是对象"类型.

Ahhh, I finally see what you're asking, you were thinking in another Programing language where there's "type". You see in JS, function is an Object. There's no class. Every Object you created will be type "Object".

这篇关于构造函数创建的对象的 __proto__ 值是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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