I am trying to execute eval within a particular context. I have found the answer here useful. However I am getting the following behavior in Chrome Version 53.0.2785.143 m.
whilst I recommend the answer provided by @trincot and in particular the great link. I am posting here my solution to the problem I faced
function evalInContext(scr, context)
{
// execute script in private context
return (new Function( "with(this) { return " + scr + "}")).call(context);
}
The with(this) expression allows the member variables of the context object to be present in the execution scope of the expression scr.
Credit to this answer to a similar question