On Sat, Jan 8, 2011 at 10:22 AM, Miller Medeiros <[email protected]>
 wrote:

> On Fri, Jan 7, 2011 at 5:41 PM, Nick Morgan <[email protected]> wrote:
>
>>
>> to create a global variable. If I thought my code would be run outside of
>> a browser then I'd create a global object as Dmitry P suggested.
>>
>>
> If you want to run it outside the browser you can always create a `window`
> variable that points to the global scope... I don't like the idea of naming
> the variable as `global` since almost all the code "in the wild" uses window
> to reference something that should be global.
>
>
It cannot circumvent the problem at hand; Mathias put the case such that
your code might be embedded (not concatenated) in other code. And that your
assumptions about global scope might be invalid. In that case, your pattern
doesn't (and can't) guarantee that window is in fact the global object.

Hm. Hey, in non-strict mode you could probably do something like `var global
= (function(){return this;}())` to get global. In strict mode, I'm not even
sure whether it'd be that easy. That was kind of the point too ;)

- peter

-- 
To view archived discussions from the original JSMentors Mailman list: 
http://www.mail-archive.com/[email protected]/

To search via a non-Google archive, visit here: 
http://www.mail-archive.com/[email protected]/

To unsubscribe from this group, send email to
[email protected]

Reply via email to