I have some code return from server like "var myVar = 314;", I would like to create a context object like so var context = {}; and then eval the script "var myVar = 314;" into properties of context, how could I achieve this ?
I have tried the below code, but without success:
var context = {};
eval.call(context, "var myVar = 314;");
EDIT May be I wasn't clear enough in the first place, the result I expected is: after eval(), I got the properties in the context object, the aim is to avoid global scope population.
For example,
var context = {};
eval.call(context, "var myVar = 314;");
I would expect the result as context.myVar = 314.