“下面的值是刚刚评估的",是什么意思? [英] "Value below was evaluated just now", what does it mean?

查看:48
本文介绍了“下面的值是刚刚评估的",是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

伙计们!我试图列出使用 new 关键字创建实例时幕后发生的事情.

Folks! I am trying to list down what happens behind the scenes when new keyword is used to create an instance.

这是我的代码的样子

function F() {}
let f1 = new F()
f1.__proto__

到目前为止我的理解是,当使用 new 时,会创建一个具有以下两件事的新对象

When I understood so far is that when new is used, a new object is created with following 2 things

{
  constructor: f <-- this is the constructor function F(), referring to itself
  __proto__: Object <-- since this is not sub-classing any other Object, every object except Object inherits from Object.prototype
}

这种理解正确吗?

当我运行它时,我在 Google Developer Console 中得到以下内容

As I run this, I get the following in the Google Developer Console

下面的值刚刚求值是什么意思?

谢谢

推荐答案

简而言之,控制台会在您按下展开图标时评估对象.这是一个测试.

Simply what it says is that the console evaluated the object just as you press the expand icon. Here is a test.

  1. 在控制台中输入 o = {}.输出将类似于 >{}.不要扩展!

  1. Type o = {} in the console. The output will be something like >{}. DON'T EXPAND YET!

o 对象添加属性.o.x = 1

现在返回并展开之前的输出.它将具有您在创建该输出后明显添加的 x 属性.但是输出仍然具有 x 值.

Now go back and expand the previous output. It will have the x property you added obviously after that output was created. But the the output still have the x value.

因为……

该值是在您展开输出时计算的,而不是在创建时计算的.

The value was evaluated right at the time you expanded the output - not the time it was created.

这篇关于“下面的值是刚刚评估的",是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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