I\'m trying to add elements to an array that are lazy-evaluated. This means that the value for them will not be calculated or known until they are accessed. This is like a p
I don't particularly like this answer, but could you store your "variable" as an expression string, and then eval() it when you need it? Not ideal, but it's compact...
var x = 10, arr = [];
arr.push("x + 10");
alert(eval(arr[0]));
x = 20;
alert(eval(arr[0]));
I've tested it, and it works, even if it's not exactly what you're looking for.