0
Is there any way to define the value of an object to be equal to the previous object?
Example:
var obj = {a: 1, b: obj.a};
I tried used b: this.a
also but created an html Circle tag, I did not understand why.
Actually, I’m managing to do it this way:
var obj = {a: 1, b: null};
obj.b = obj.a;
Is there any other way more effective?
Before submitting an answer I ask, would the use of a property solve your problem? Example:
var obj = {a: 1, get b(){return this.a}};
– Augusto Vasques
No, what I want is for two or more elements inside the object to have the same values. EX:
var obj = {a: 1, b: /*valor ou ponteiro de a*/, c: 2, d: /*valor ou ponteiro de c*/, e: etc...}
– Luís HNrique
Before you say it is not what you seek to do
var obj = {a: 1, get b(){return this.a}}; console.log(obj); obj.a=33; console.log(obj); console.log(obj.b);
– Augusto Vasques
I used the console.log(obj) and obj. b didn’t show up, but now I’ve seen that it does exist. Sorry, that’s what I was really looking for.
– Luís HNrique