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

Tabview code readability / possible bug.

Expand Messages
  • scottabuy
    The readability of the debug code in version: 0.12.1 has decreased in my opinion and I was wondering if there was a reason for it? In particular on line 472 of
    Message 1 of 4 , Dec 27, 2006
      The readability of the debug code in version: 0.12.1 has decreased in
      my opinion and I was wondering if there was a reason for it?

      In particular on line 472 of tabview-debug.js code looks like this
      "})();(function() {" and it is very difficult to determine what is
      going on. I understand that a function is being invoked and it appears
      that another function is going be invoked but it almost impossible to
      tell where that second function ends. Is there a reason the code is
      mushed together like this, maybe for minification?

      Also I found that the code on line 954 is create a Tab function in
      global scope, maybe this is what was intended but I though I would
      mention it.

      One other questions: What is the benefit of create objects using
      anonymous function invocation? One example would be the
      YAHOO.Util.Lang object in the tabview-debug.js file.

      (function() {
      YAHOO.Util.Lang = {
      ....
      };
      })();

      Thanks,

      Scott
    • Eric Miraglia
      Scott, The running together at line 472 is not intentional and not necessary; notice we have a line-break in a similar construct at line 938-9 of the debug
      Message 2 of 4 , Dec 27, 2006
        Scott,

        The running together at line 472 is not intentional and not necessary; notice we have a line-break in a similar construct at line 938-9 of the debug file.  We'll see about adding some spacing there for the next release.  (We don't make any effort to minify the standard and -debug versions of files; minification is only applied to the -min versions.)

        As for your question about anonymous functions, the construct does look a little odd:

        (function() {
        //function body
        })();

        Really, what that's allowing the code author to do is to create a lot of variables with function scope within that anonymous function. The best way to think of this is as a way to create a scope block and, potentially, some useful closures. Notice how the TabView code uses that scoping and closure to good effect by creating aliases within the anonymous function to frequently-referenced packages (line 939ff in -debug):

        (function() {
            var Dom = YAHOO.util.Dom,
                Event = YAHOO.util.Event,
                Lang = YAHOO.util.Lang;
        ...

        Wrapping the anonymous function in parens probably shouldn't be necessary but is necessary as a result of some early implementations of the JavaScript engine in Netscape back in the day that ultimately became part of the language.  The () at the end of the statement tells the anonymous function to execute immediately; that means the code within the function body is a lot like inline code, but it has scope and closures.

        Regarding the implied global on line 954, that's an error.  We'll get that fixed in the next release.  The variable Tab in that instance is simply a shorthand for what will become YAHOO.widget.Tab later in the script (in line 1349 of the debug version).  Thanks for catching that.

        Regards,
        Eric

        ______________________________________________
        Eric Miraglia
        Yahoo! User Interface Library


        The readability of the debug code in version: 0.12.1 has decreased in
        my opinion and I was wondering if there was a reason for it?

        In particular on line 472 of tabview-debug.js code looks like this
        "})();(function() {" and it is very difficult to determine what is
        going on. I understand that a function is being invoked and it appears
        that another function is going be invoked but it almost impossible to
        tell where that second function ends. Is there a reason the code is
        mushed together like this, maybe for minification?

        Also I found that the code on line 954 is create a Tab function in
        global scope, maybe this is what was intended but I though I would
        mention it.

        One other questions: What is the benefit of create objects using
        anonymous function invocation? One example would be the
        YAHOO.Util.Lang object in the tabview-debug.js file.

        (function() {
        YAHOO.Util.Lang = {
        ....
        };
        })();

        Thanks,

        Scott


      • scottabuy
        Eric, Thanks for the quick response and great explanations. Scott
        Message 3 of 4 , Dec 28, 2006
          Eric,

          Thanks for the quick response and great explanations.

          Scott
        • rizzi_john
          ... Thank you, Scott, for asking the question about the anonymous function invocation that I and perhaps others were hesitant to ask and to the Yahoo! team for
          Message 4 of 4 , Dec 30, 2006
            --- In ydn-javascript@yahoogroups.com, "scottabuy" <scottabuy@...> wrote:
            >
            > Eric,
            >
            > Thanks for the quick response and great explanations.
            >
            > Scott
            >

            Thank you, Scott, for asking the question about the anonymous function
            invocation that I and perhaps others were hesitant to ask and to the
            Yahoo! team for being so responsive.

            Happy New Year!

            John
          Your message has been successfully submitted and would be delivered to recipients shortly.