how to object value to its on property object ?
I tried like this
var obj = {
a:2,
b:this.a
}
Then try obj.b
it is giving undefined
..can I make function in object?
Expected output 2
how to object value to its on property object ?
I tried like this
var obj = {
a:2,
b:this.a
}
Then try obj.b
it is giving undefined
..can I make function in object?
Expected output 2
const obj = {
a: 2,
get b() {
return this.a;
}
};
console.log(obj.b);
const obj2 = {
a: 2,
b: function() {
return this.a;
}
};
console.log(obj2.b());
See it in action: https://jsfiddle.net/rqnbxw86/