Below a sample version of the code I'm having problems with. I have a dynamic function that I use at some other place in order to dynamically select certain attributes, e.g., as shown here blabla.years.y2011.hello. However, this does not work, and I've found out that the variable 'o' here is not replaced by its actual value, e.g., hello or bye but just stays o (see second listing). How can I dynamically use the value of o in the return line?
for (var o in ["hello", "bye"]) {
somevar[o] = {
"f": function(x) {
return x["years"]["y2011"][o];
}
...
Output of console.log of somevar["hello"]:
function (x) {
return x["years"]["y2011"][o];
}
As you can see, o is not replaced by the value hello or bye but just stays o.