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

Re: bug in event.js?

Expand Messages
  • isaac_schlueter
    ... Peter, I don t think it s a trick for JSDoc. It s a closure, and it s how you make private variables in Javascript.
    Message 1 of 4 , Aug 31 5:11 PM
    • 0 Attachment
      --- In ydn-javascript@yahoogroups.com, "Peter Michaux"
      <petermichaux@...> wrote:
      > Maybe you guys were playing a trick to get JSDoc to pick
      > up the documentation since it can't document objects?

      Peter,

      I don't think it's a trick for JSDoc. It's a closure, and it's how
      you make private variables in Javascript.

      http://javascript.crockford.com/private.html

      //------------//
      (function(){
      var a='private';
      YAHOO.namespace('myObj').getA = function(){ return a; };
      })();
      alert(YAHOO.myObj.getA()); // "private"
      alert(a); // Exception: "a is not defined"
      a=2;
      alert(YAHOO.myObj.getA()); // "private" -- window.a !== private a
      //------------//

      Note that now objects outside the closure can't overwrite the value of
      a. There's no worry that my variable named "a" might overwrite the
      value of your script's variable named "a". Careful scoping is a best
      practice, especially when writing code for mass consuption.

      --
      Isaac Z. Schlueter
      Webdev, Yahoo! Games
    Your message has been successfully submitted and would be delivered to recipients shortly.