So, I have this piece of code:
const test = {
prop: 42,
func: function() {
return this.prop;
},
something: this.prop,
};
console.log(test.func());
// expected output: 42, which we are getting. But...
console.log(test.something);
// expected output: 42, here the output is `undefined`.
I want that something
to be the prop
property of the same object. And the function propery gives the value back, but when I log the something
property it gives undefined
.
I tried this in the node.js
and in the browser
too.
Why is this happening and can somebody get this to work please?