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.
many libraries uses this kind of pattern:
(function(window){
window.myLibrary = {};
})(window);
which makes it easy to switch where your modules should be exported to:
(function(window){
window.myLibrary = {};
})(myAwesomeEnvironment);
closure compiler even uses window to "export the symbols you want to keep":
http://code.google.com/closure/compiler/docs/api-tutorial3.html#removal
I can understand why you guys are saying that the "global" approach is
better but I think it may confuse people..
--
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]