Clean scope

Andrew Oakley andrew at
Wed Aug 17 11:48:51 PDT 2011

On Wed, 17 Aug 2011 10:38:43 -0700
John J Barton <johnjbarton at> wrote:

> On Wed, Aug 17, 2011 at 9:14 AM, Juriy Zaytsev <kangax at>
> wrote:
> > What do you mean by "clean scope"? All scope chains have at least
> > global scope in them. Is that what "clean scope" chain would be —
> > the one including global scope only? That's pretty much what
> > `Function` constructor does.
> No, I mean a scope with JavaScript built-ins only, no 'host'
> functions,  no |window| properties.
> function walkTheWalk(position) {
>   "use empty";
>    var from = parent.location; // error, should have said
> position.parent, but it works?!?
> }

There really isn't a nice way to do this.  I don't think that using
function constructors or eval improve things in any way.

Perhaps a lint program could be modified to detect this?  You could use
a "use ..." prologue to indicate to the linter that this is desired.
Douglas Crockford's JSLint contains a full blown parser and could
probably be modified to do this fairly easily.

Andrew Oakley

More information about the es-discuss mailing list