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

Try to use a single 'var' statement per scope.

Expand Messages
  • Fred Lorrain
    Hello, Is it a good practice to try to use a single var statement per scope? For sure it help the compression of the script. If it s a best practice can an
    Message 1 of 5 , Aug 14, 2008
    • 0 Attachment
      Hello,

      Is it a good practice to try to use a single 'var' statement per scope?
      For sure it help the compression of the script.
      If it's a best practice can an option in JSLint generate a warning.

      I'm using yuicompressor-2.3.5.jar to compress my scripts and this tool
      typically return such kind of warning:

      [WARNING] Try to use a single 'var' statement per scope.
      ?e.innerText:e.text; ---> var <--- ttl="";if(myText){ttl
    • Douglas Crockford
      ... I don t understand this.
      Message 2 of 5 , Aug 14, 2008
      • 0 Attachment
        --- In jslint_com@yahoogroups.com, "Fred Lorrain" <yahoo@...> wrote:
        > Is it a good practice to try to use a single 'var' statement per scope?
        > For sure it help the compression of the script.
        > If it's a best practice can an option in JSLint generate a warning.
        >
        > I'm using yuicompressor-2.3.5.jar to compress my scripts and this tool
        > typically return such kind of warning:
        >
        > [WARNING] Try to use a single 'var' statement per scope.
        > ?e.innerText:e.text; ---> var <--- ttl="";if(myText){ttl

        I don't understand this.
      • Arthur Blake
        I think he s trying to ask if it is better to use this form: var x,y,z; versus var x; var y; var z; My opinion is yes, because it makes the script smaller and
        Message 3 of 5 , Aug 14, 2008
        • 0 Attachment
          I think he's trying to ask if it is better to use this form:

          var x,y,z;

          versus

          var x;
          var y;
          var z;

          My opinion is yes, because it makes the script smaller and also could help reinforce the fact that the var keyword is only at function scope.

          On Thu, Aug 14, 2008 at 11:33 AM, Douglas Crockford <douglas@...> wrote:

          --- In jslint_com@yahoogroups.com, "Fred Lorrain" <yahoo@...> wrote:
          > Is it a good practice to try to use a single 'var' statement per scope?
          > For sure it help the compression of the script.
          > If it's a best practice can an option in JSLint generate a warning.
          >
          > I'm using yuicompressor-2.3.5.jar to compress my scripts and this tool
          > typically return such kind of warning:
          >
          > [WARNING] Try to use a single 'var' statement per scope.
          > ?e.innerText:e.text; ---> var <--- ttl="";if(myText){ttl

          I don't understand this.


        • Douglas Crockford
          ... could help ... Thanks, I get it now. I think it is a good suggestion.
          Message 4 of 5 , Aug 14, 2008
          • 0 Attachment
            --- In jslint_com@yahoogroups.com, "Arthur Blake" <arthur.blake@...>
            wrote:
            >
            > I think he's trying to ask if it is better to use this form:
            >
            > var x,y,z;
            >
            > versus
            >
            > var x;
            > var y;
            > var z;
            >
            > My opinion is yes, because it makes the script smaller and also
            could help
            > reinforce the fact that the var keyword is only at function scope.

            Thanks, I get it now. I think it is a good suggestion.
          • Fred Lorrain
            ... The new onevar option can now be used to that
            Message 5 of 5 , Aug 18, 2008
            • 0 Attachment
              --- In jslint_com@yahoogroups.com, "Douglas Crockford" <douglas@...>
              wrote:
              >
              > --- In jslint_com@yahoogroups.com, "Arthur Blake" <arthur.blake@>
              > wrote:
              > >
              > > I think he's trying to ask if it is better to use this form:
              > >
              > > var x,y,z;
              > >
              > > versus
              > >
              > > var x;
              > > var y;
              > > var z;
              > >
              > > My opinion is yes, because it makes the script smaller and also
              > could help
              > > reinforce the fact that the var keyword is only at function scope.
              >
              > Thanks, I get it now. I think it is a good suggestion.
              >


              The new 'onevar' option can now be used to that
            Your message has been successfully submitted and would be delivered to recipients shortly.