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

Re: onevar

Expand Messages
  • santini.alberto
    ... [cut] ... I modified my code conventions. Before I wrote for the inner functions var my_function = function () { ... } Now, modifying the code complaining
    Message 1 of 6 , Sep 3, 2008
    • 0 Attachment
      --- In jslint_com@yahoogroups.com, "Douglas Crockford" <douglas@...>
      wrote:
      >
      > I added a onevar option. It allows only one var statement per function.
      >
      [cut]
      >
      > There are a lot of changes in this update. Please let me know if I
      > broke anything.
      >

      I modified my code conventions.

      Before I wrote for the inner functions

      var my_function = function () {
      ...
      }

      Now, modifying the code complaining with onevar option, I have been
      writing

      function my_function() {
      ...
      }

      So I have not to define at the beginning of the (outer) function the
      variable containing the (inner) function.

      I know the two style are equivalents, but I was wondering if there is
      a subtle difference, maybe about the scope, I am missing. What is your
      style?

      Thanks in advance,
      Alberto Santini
    • ojacquem
      Hello, ... function. ... Personally I don t think this practice should be recommended. It contradicts the related recommendation in the Code Conventions
      Message 2 of 6 , Oct 17, 2008
      • 0 Attachment
        Hello,

        --- In jslint_com@yahoogroups.com, "Douglas Crockford" <douglas@...>
        wrote:
        >
        > I added a onevar option. It allows only one var statement per
        function.
        >
        Personally I don't think this practice should be recommended.
        It contradicts the related recommendation in the Code Conventions
        <http://javascript.crockford.com/code.html> page :-)

        It is preferred that each variable be given its own line and comment.
        (...)
        var currentEntry; // currently selected table entry

        var level; // indentation level
        var size; // size of table
        With a single var statement, all variables will typically be defined on
        the same line without comments, decreasing readability &
        maintainability.
        "Small code is more efficient in JavaScript"? This is the job of a
        minifier.

        Suggestion: check that all var statements are grouped at the beginning
        of the function. This will guarantee that scope problems are avoided,
        which was the purpose of introducing onevar, as I understand it.



        [Non-text portions of this message have been removed]
      • Jakob Kruse
        What s wrong with: var var1, // comment var2, // comment var3; // comment It usually works for me. /Jakob ... From: ojacquem To: jslint_com@yahoogroups.com
        Message 3 of 6 , Oct 17, 2008
        • 0 Attachment
          What's wrong with:

          var var1, // comment
          var2, // comment
          var3; // comment

          It usually works for me.

          /Jakob


          ----- Original Message -----
          From: ojacquem
          To: jslint_com@yahoogroups.com
          Sent: Friday, October 17, 2008 3:36 PM
          Subject: [jslint] Re: onevar


          Hello,

          --- In jslint_com@yahoogroups.com, "Douglas Crockford" <douglas@...>
          wrote:
          >
          > I added a onevar option. It allows only one var statement per
          function.
          >
          Personally I don't think this practice should be recommended.
          It contradicts the related recommendation in the Code Conventions
          <http://javascript.crockford.com/code.html> page :-)

          It is preferred that each variable be given its own line and comment.
          (...)
          var currentEntry; // currently selected table entry

          var level; // indentation level
          var size; // size of table
          With a single var statement, all variables will typically be defined on
          the same line without comments, decreasing readability &
          maintainability.
          "Small code is more efficient in JavaScript"? This is the job of a
          minifier.

          Suggestion: check that all var statements are grouped at the beginning
          of the function. This will guarantee that scope problems are avoided,
          which was the purpose of introducing onevar, as I understand it.

          [Non-text portions of this message have been removed]





          [Non-text portions of this message have been removed]
        Your message has been successfully submitted and would be delivered to recipients shortly.