July 30, 2017

Don't refer a child from another child when declaring an obj

Apparently, in declaring an obj, a child cannot be assign or refer to another child within the same obj which is being declared.

let obj = {
	a: 1,
	b: 3,
};

console.log(obj.c);
// => undefined

Instead, declare function to re-access the obj like this

let obj2 = {
	a: "it",
	b() {
		return this.a + " works";
	},
};

console.log(obj2.b());
// => it works