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

Re: [jslint] window (UNCLASSIFIED)

Expand Messages
  • Cheney, Edward A SSG RES USAR USARC
    Classification: UNCLASSIFIED ... var o = { // global object first: function (xyz) { return xyz; }, second: function (abc) { return abc; } }; o.first(); // this
    Message 1 of 1 , Mar 30, 2011
    • 0 Attachment
      Classification: UNCLASSIFIED


      On 03/29/11, 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)?
      >

      var o = { // global object
      first: function (xyz) {
      return xyz;
      },
      second: function (abc) {
      return abc;
      }
      };

      o.first(); // this executes the first function from above
      o.second(); // this executes the second function from above

      This works because the functions are members of a named object, therefore
      the functions are references as object properties bound to the named object.

      My suggestion is to never use this:
      function nameof () {}

      Instead always use either the form in the example or this form:
      var asdf = function () {};

      If this fails to answer your question please let me know.

      Austin Cheney, CISSP
      http://prettydiff.com/

      Classification: UNCLASSIFIED
    Your message has been successfully submitted and would be delivered to recipients shortly.