Is it possible when you create an object to use the same properties?

For example, instead of:
o = {
 x : a + b,
 y : a + b,
}

To write something like this:
o = {
 x : a + b,
 y : o.x
}
March 19th 20 at 08:23
1 answer
March 19th 20 at 08:25
Solution
You can just run in the console and check out what is to be done, and if you simply explain it:
1) first we created the object (what is between { ... });
2) if the property specified some expression (tipo a+b, or obj.property) , it is evaluated and the result of this expression becomes the value of this property;
3) let's say we have something like this -
let o = {
 x : 2,
 y : o.x
}

Property x gets the value 2 and reach the properties of y we see there, the properties x of the object o, but we still do not have a variable named o, which means we just can't get the property, and we have not found the object and eventually get a ReferenceError.
4) If we had no errors and the object is successfully created and placed in memory, only then is created in the right scope variable that is assigned a reference to our object, and only then we can refer to it for the specified name.

Find more questions by tags JavaScript