How to modify the scope chain without `with` ?

Andreas Rossberg rossberg at google.com
Tue Feb 16 07:51:56 UTC 2016


On 15 February 2016 at 18:49, Coroutines <coroutines at gmail.com> wrote:

> On Mon, Feb 15, 2016 at 4:48 AM, Benjamin Gruenbaum <inglor at gmail.com>
> wrote:
> > For what it's worth very popular templating libraries like KnockoutJS use
> > `woth` heavily.
> >
> > I think the consensus is that writing DSLs should be done as a
> > transformation into JavaScript (like JSX) and not inside JavaScript (like
> > Knockout and your library)
> >
> > The dynamic nature of `with` is why it is forbidden in strict mode, when
> > import/export land in browsers things will run in strict mode by default
> > which means `with` is gone.
>
> Aside from this, I wish JS would provide the ability to modify the
> scope chain - and it should be just objects that can inherit from one
> another through prototypes.  I think it would be too perfect/clean to
> handle scope in the existing way we handle inheritance.  My example
> isn't completely justified to say "I need this" - but I think having
> direct control over scope would be important in the future and should
> be considered for ES7.  Especially if the existing way is not portable
> anymore...
>

That would be a total and complete disaster for implementations, as it
would make scopes observable and mutable in a way that absolutely breaks
all conventional compilation and optimisation techniques for local
variables, closures, etc. JavaScript would easily become 10-100x slower.
Like when you use `with` today.

I don't think it would be a security concern either, as you could only
> make objects you have reference to your new scope.
>

It would totally break security as well, given that functions could then
peek into local variables on their call chain through __proto__. And I
cannot even fathom what it would mean to mutable some __proto__!

/Andreas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20160216/5a064933/attachment.html>


More information about the es-discuss mailing list