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

Re: [ydn-javascript] bug in event.js?

Expand Messages
  • Adam Moore
    ... No, this is a private variable declared near the top of the file, and used throughout the utility. -Adam
    Message 1 of 4 , Aug 31, 2006
      On Thu, Aug 31, 2006 at 03:52:48PM -0700, Peter Michaux wrote:
      > Hi,
      >
      > I've been reading the event.js file and found something suspicious. In
      > the attached _unload function there is the line
      >
      > if (listeners && listeners.length > 0) {
      >
      > but there isn't a local variable in the function called "listeners".
      > Should it really be...
      >
      > if (this.listeners && this.listeners.length > 0) {

      No, this is a private variable declared near the top of the file, and used
      throughout the utility.

      -Adam
    • Peter Michaux
      ... Hi Adam, Thanks. I can see what is going on now. It s a bit different than how I do things. Maybe you guys were playing a trick to get JSDoc to pick up the
      Message 2 of 4 , Aug 31, 2006
        On 8/31/06, Adam Moore <adamoore@...> wrote:
        >
        > On Thu, Aug 31, 2006 at 03:52:48PM -0700, Peter Michaux wrote:
        > > Hi,
        > >
        > > I've been reading the event.js file and found something suspicious. In
        > > the attached _unload function there is the line
        > >
        > > if (listeners && listeners.length > 0) {
        > >
        > > but there isn't a local variable in the function called "listeners".
        > > Should it really be...
        > >
        > > if (this.listeners && this.listeners.length > 0) {
        >
        >
        > No, this is a private variable declared near the top of the file, and used
        > throughout the utility.
        >

        Hi Adam,

        Thanks. I can see what is going on now. It's a bit different than how
        I do things. Maybe you guys were playing a trick to get JSDoc to pick
        up the documentation since it can't document objects? I was told by
        someone in the JSDoc camp that they are going to change things so the

        var foo = function(){}();

        trick doesn't have to be used. It may take a long time for them to get
        there however.

        Thanks again,
        Peter
      • 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 3 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?

          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.