0

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

Here is what my code looks like

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

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
}

Is this understanding correct?

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

enter image description here

What does Value below was evaluated just now mean?

Thanks

Charlie
  • 22,886
  • 11
  • 59
  • 90
daydreamer
  • 87,243
  • 191
  • 450
  • 722
  • 1
    Exactly what it says. The object you've logged to the console has just been evaluated and it might show a different value then when it was logged to the console. A quick (re-)search would also have explained the message. – Andreas Sep 08 '19 at 16:31
  • See https://stackoverflow.com/q/23392111 – Bergi Sep 08 '19 at 16:35
  • `f1.__proto__` will be set to `F.prototype`, which is `Object` because it hasn't been set to anything else. – Paul Sep 08 '19 at 16:37

2 Answers2

4

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

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

  2. Add a property to the o object. o.x = 1

  3. 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.

Because...

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

Charlie
  • 22,886
  • 11
  • 59
  • 90
1

Value below was evaluated just now

Basically means that what you are seeing is the value of the object at the moment you're viewing it in the console. This is useful info in case you're using for example console.log(someObject) in your app code.

What it's telling you is that what you're seeing in the browser console is the current value of someObject, and not necessarily the value that object had at the moment console.log was executed (the object may have been different at that point in code execution).

Basically this is because it's just referencing the object, and the properties/methods are not visible until you expand it in the console window.

Vexter
  • 1,172
  • 11
  • 12