How to modify the scope chain without `with` ?

Coroutines coroutines at
Tue Feb 16 17:37:40 UTC 2016

On Tue, Feb 16, 2016 at 9:16 AM, /#!/JoePea <joe at> wrote:
> /#!/JoePea
> On Feb 16, 2016 9:13 AM, "/#!/JoePea" <joe at> wrote:
>> Seems like changing the global could lead to problems where a developer
>> might assumes certain globals but hey
> I meant: "but have" different ones. Importing things explicitly into modules
> (instead of (inherited) globals) helps better understand the requirements of
> a given piece of code imo.
>> different ones, which imho could make the use of globals even messier. I
>> imagine you would like Angular's $scope inheritance, which is sort of like
>> what you want
>> (

I was just thinking about the `import` we gained in ES6.  In Perl and
Python you might have functions imported directly into the global
scope (of the current context) - so that it's easier to just write the
function name without the short reference you imported it in as:

cos(PI) vs Math.cos(Math.PI)  etc...

I was simply thinking it could give you the ability to choose how you
prefer to write that.  If you're not using several modules and the
code you're writing is quite focused in one area it might look cleaner
(less redundant) to import Math and have all its functions be
accessible as "globals".  If you are writing code that ties together
functions from Math, fs, and tls modules (for some reason??) it would
make sense to do the existing:

var fs = require('fs');
var tls = require('tls');

Anyway, if we had control over the global scope/context/Object, it
would allow you to make these design decisions in an effort to write
code that I would sometimes view as cleaner.  What I think is
important is that you could have your existing scope inherit from the
"first" global scope, but when you assign to the current global scope
it is set there.  Your modifications don't extend globally to the rest
of the project.  Also if you want to isolate your current scope from
the global scope you don't have to have one inherit from the other -
you can break it's prototype (or never form it).  Again, as the other
guy pointed out - it's not a complete or even marginally safe
"sandbox" but all in all I think it's something we should have control
over if we want to simplfy how modules are created (for one) without
polluting the existing global scope/Object.

My responses are a bit wordy/disorganized...

More information about the es-discuss mailing list