Loading ...
Sorry, an error occurred while loading the content.

2086Re: window

Expand Messages
  • jeddahbill
    Mar 30, 2011
    • 0 Attachment
      What has worked well for me is to create a namespace based on one's domain name, or a domain name that one owns.

      This is discussed in some detail by David Flanagan in his book, JavaScript: The Definitive Guide (O'Reilly), Paragraph 10.1. See Example 10.1, Creating a namespace based on a domain name.

      In short, assuming domain name, 'mydomain.com', after going through the coding wickets, you end up with something like this:
      // at global scope...
      com.mydomain = {};

      Then, to add (or "require") a new module 'abc' to your namespace:
      if (!com.mydomain.abc) {com.mydomain.abc = (function () {/* lots of code that returns something */}());}

      --- In jslint_com@yahoogroups.com, Erik Eckhardt <erik@...> wrote:
      >
      > If you were creating a specialized code library, what method would you use
      > to "namespace" all the functions in use by that library? Since functions are
      > themselves globals, would you just create a single "master" object, itself
      > global, with all other variables inside of it? Then, in commons use, either
      > use this.fn() or libraryname.fn() all over the place instead of just fn()
      > when you want to use a function? And something similar for any variables
      > that are needed to control the operation of the code library (say it's a
      > popup widget that needs to keep track of all the open popups and whether a
      > particular popup template has been loaded via ajax or not)?
      >
      > On Tue, Mar 29, 2011 at 8:57 AM, Douglas Crockford <douglas@...>wrote:
      >
      > >
      > >
      > > --- In jslint_com@yahoogroups.com, Erik Eckhardt <erik@> wrote:
      > >
      > > > Is there some place an interested person could read about the good vs.
      > > bad
      > > > uses of `window`?
      > >
      > > The principle misuse is to access global variables. Global variables should
      > > be avoided.
      > >
      > >
      > >
      >
      >
      > [Non-text portions of this message have been removed]
      >
    • Show all 9 messages in this topic