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

Re: window

Expand Messages
  • jeddahbill
    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
    Message 1 of 9 , Mar 30 9:25 AM
    • 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]
      >
    • Alexandre Morgaut
      My biggest nightmare today is that recent browsers like Chrome, IE9, FF4 generate a global variable from the id of each HTMLElement of the document... It is
      Message 2 of 9 , Mar 31 5:08 AM
      • 0 Attachment
        My biggest nightmare today is that recent browsers like Chrome, IE9, FF4 generate a global variable from the id of each HTMLElement of the document...

        It is know possible in these browser to write

        domNode = myPanel;

        or

        domNode = window.myPanel;

        instead of

        domNode = document.getElementById('myPanel');

        or with jQuery:

        domNode = $('#myPanel');

        Let's imagine the effects of existing HTMLElements with id like "location", "document", "event", "toolbar", or even "window"...

        What should be the list of reserved keywords for valid id value ?
        All the BOM API ?
        + APIs like Web Storages, Web Sockets... ?
        + Global namespaces of common Ajax frameworks ?

        And what about future HTML5/W3C APIs ?
        And what about future or private frameworks ???

        So ... "window.myPanel"
        -> Bad practice isn't it ?
      • AJ ONeal
        That is a nightmare! I just noticed that a few days ago and it was really upsetting to see even MORE global leakage... YUCK. AJ ONeal ... [Non-text portions of
        Message 3 of 9 , Mar 31 8:45 AM
        • 0 Attachment
          That is a nightmare!

          I just noticed that a few days ago and it was really upsetting to see even
          MORE global leakage... YUCK.

          AJ ONeal


          On Thu, Mar 31, 2011 at 6:08 AM, Alexandre Morgaut <morgaut@...>wrote:

          >
          >
          > My biggest nightmare today is that recent browsers like Chrome, IE9, FF4
          > generate a global variable from the id of each HTMLElement of the
          > document...
          >
          > It is know possible in these browser to write
          >
          > domNode = myPanel;
          >
          > or
          >
          > domNode = window.myPanel;
          >
          > instead of
          >
          > domNode = document.getElementById('myPanel');
          >
          > or with jQuery:
          >
          > domNode = $('#myPanel');
          >
          > Let's imagine the effects of existing HTMLElements with id like "location",
          > "document", "event", "toolbar", or even "window"...
          >
          > What should be the list of reserved keywords for valid id value ?
          > All the BOM API ?
          > + APIs like Web Storages, Web Sockets... ?
          > + Global namespaces of common Ajax frameworks ?
          >
          > And what about future HTML5/W3C APIs ?
          > And what about future or private frameworks ???
          >
          > So ... "window.myPanel"
          > -> Bad practice isn't it ?
          >
          >
          >


          [Non-text portions of this message have been removed]
        • AJ ONeal
          I use this pattern: https://github.com/coolaj86/require-kiss-js I m also going to look into RequireJS in the near future. AJ ONeal ... [Non-text portions of
          Message 4 of 9 , Mar 31 8:49 AM
          • 0 Attachment
            I use this pattern:
            https://github.com/coolaj86/require-kiss-js

            I'm also going to look into RequireJS in the near future.

            AJ ONeal

            On Tue, Mar 29, 2011 at 5:17 PM, 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]
            >
            >
            >
            > ------------------------------------
            >
            > Yahoo! Groups Links
            >
            >
            >
            >


            [Non-text portions of this message have been removed]
          Your message has been successfully submitted and would be delivered to recipients shortly.