Recently I tried to create an object using object literal. And I need a property that use another property in the object. Like this
var object = {
property1:'property1',
property2:'property2 is from ' + this.property1
};
console.log(object.property2);// property2 is from undefined
The this.property1
is undefined
in the property2
.
I do know many ways to deal with this problem. My question is what happens behind the scenes? In other words, how javascript engine interpret object literal? I know "hoisting" happens in the function. Does "hoisting" happens in object literal?
Thanks.