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

RE: [jslint] window

Expand Messages
  • Rob Richardson
    Could this only be enabled if one opts into use strict ? Rob ... From: jslint_com@yahoogroups.com [mailto:jslint_com@yahoogroups.com] On Behalf Of Douglas
    Message 1 of 9 , Mar 29, 2011
      Could this only be enabled if one opts into "use strict"?

      Rob


      -----Original Message-----
      From: jslint_com@yahoogroups.com [mailto:jslint_com@yahoogroups.com] On
      Behalf Of Douglas Crockford
      Sent: Tuesday, March 29, 2011 8:14 AM
      To: jslint_com@yahoogroups.com
      Subject: [jslint] window

      The Assume a browser option now includes 'window. Most uses of window are in
      support of bad practices, but some uses of it are now required by
      ES5/strict. For example,

      addEventListener(...);

      will probably fail in strict mode, while

      window.addEventLister(...);

      will probably succeed because strict mode no longer binds this to the global
      object in function form invocations.
    • Erik Eckhardt
      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
      Message 2 of 9 , Mar 29, 2011
        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]
      • 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 3 of 9 , Mar 30, 2011
          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 4 of 9 , Mar 31, 2011
            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 5 of 9 , Mar 31, 2011
              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 6 of 9 , Mar 31, 2011
                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.