In the function below, I want to pass two arguments. instance
refers to an object, prop
refers to an object property name.
door.x = 20; // door['x'] refers to the same
key(door, 'x');
function key(instance, prop) {
Tween.get(instance, {override: true}).to({prop: -150}, instance[prop]);
}
Because I need to be able to refer to door['x']
at one point (which is another way of writing door.x
), x
always need to be a string. However, the same x
here needs to be used here as an object property name, but I can't have a string there, because the code would not work:
Tween.get(door, {override: true}).to({'x': -150}, door['x']); // does not work because a string has been passed as an object property name
What I really want is this:
Tween.get(door, {override: true}).to({x: -150}, door['x']); // works
So, my question is: is there some sort of method which allows me to 'unstring' a string? Or is there perhaps any other solution around this?