global object in strict mode

Aymeric Vitte vitteaymeric at
Fri Aug 24 15:51:18 PDT 2012

We don't know what name has 'global' (ie var global=this, var 
window=this, etc)

This is what I tried to figure out here among others : ("automatic", 
window.window=window), maybe impossible, unlikely, or whatever

I don't know well about this CSP proposal but it seems strange to me 
everytime something states that 'eval' is forbidden or stuff like this, 
a 'wrap' or equivalent would be better

Le 24/08/2012 19:51, Brendan Eich a écrit :
> Kris Kowal wrote:
>> On Fri, Aug 24, 2012 at 10:41 AM, Brendan Eich<brendan at>  
>> wrote:
>>> I'm not sure what the problem is -- I read the old thread, and 
>>> noticed the
>>> solution:
>>> var global = Function("return this")();
>>> This is good for any code mode, strict or non-strict. Does CSP ban 
>>> Function
>>> as well as eval?
>> CSP does forbid the Function constructor, by the edict “Code will not
>> be created from strings”.
>> Section 4.2 “If unsafe-eval is not allowed…”
> Sure, makes sense (I think I even knew that once -- have to catch up 
> on CSP when I have some time, next millennium :-P).
> Is it common to want an expression, usable in any context (non-strict, 
> strict, CSP, deep in a function nest with potentially many names in 
> scope, some of which might shadow globals), that evaluates to "the 
> current global object"?
> JS libraries do things like
> (funciton (global) {
>   // all the code here
> })(this);
> and that works, as well as the brute force
> var global = this;
> approach. But one must take care not to shadow the name.
> Could ES6 add a predefined global property named 'global', set to 
> reference the global object? I suppose maybe - it would be writable or 
> (to use WebIDL's term) [Replaceable]. We can't just make a const 
> global, we will break extant code.
> Is this global global important to standardize?
> /be
> _______________________________________________
> es-discuss mailing list
> es-discuss at

Email :  avitte at
Web :
Webble :
Extract Widget Mobile :
BlimpMe! :

More information about the es-discuss mailing list