Pass an environment to eval()?

Brendan Eich brendan at mozilla.com
Sat Sep 28 15:06:53 PDT 2013


> Axel Rauschmayer <mailto:axel at rauschma.de>
> September 28, 2013 2:49 PM
> Has this feature ever been considered?

Lots of times, going back at least as far as

http://wiki.ecmascript.org/doku.php?id=discussion:resurrected_eval

Read under "Resolved issues".

SpiderMonkey had a two-argument eval for ages, from before the modern 
era. We removed it. No one should be messing with the signature of eval 
at this point.

Module loader API supersedes all such ideas in ES6.

/be
>
> For example:
>
> ```
> $ var env = { __proto__: window, foo: 1 };
> $ eval('var bar = foo+1', env);
> $ env.bar
> 2
> ```
>
> Useful for writing interpreters and more convenient for interacting 
> with evaluated code than improvising something equivalent via `Function`.
>
> Axel
>
> -- 
> Dr. Axel Rauschmayer
> axel at rauschma.de <mailto:axel at rauschma.de>
>
> home: rauschma.de <http://rauschma.de>
> twitter: twitter.com/rauschma <http://twitter.com/rauschma>
> blog: 2ality.com <http://2ality.com>
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss


More information about the es-discuss mailing list