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, 2006
      --- 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?


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


      var a='private';
      YAHOO.namespace('myObj').getA = function(){ return a; };
      alert(YAHOO.myObj.getA()); // "private"
      alert(a); // Exception: "a is not defined"
      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.