I have some trouble using the Object properties. I want to evaluate an expression within the myObject
context to avoid using the myObject.property
.
My final goal is to evaluate a more complex expression like 'property1+property2'
instead of 'myObject.property1+myObject.property2'
.
I have tried the call method to change the context but, it doesn't seem to see the Object properties in the passed context(i.e. the Object containing the properties)(see the last line of the code below generating the error).
var myObject = {
property1: 20,
property2: 5000
};
print(myObject.property1); // return 20
print(eval.call(myObject,property1)); // ReferenceError: property1 is not defined
Is there any way to use the Object properties without the usage of this.
or myObject.
prefix?