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

var declaration at the top of the page and other newbie JSLint questions

Expand Messages
  • Eric
    Hello, I have a function that I ve written that s not behaving as expecting. I ran JSLint on it, it didn t really fix my problem, but I had a few questions
    Message 1 of 3 , Feb 2, 2011
    • 0 Attachment
      Hello,

      I have a function that I've written that's not behaving as expecting. I ran JSLint on it, it didn't really fix my problem, but I had a few questions about it's recommendations.

      The first thing I noticed was that JSLint didn't want to just analyze my function, I had to put in the tags in the text that it analyzed to make it a legitimate HTML document. Are there any settings that will allow you do analyze JavaScript outside of an HTML document? What would you do if, for instance, you had a standalone .js file you wanted to analyze?

      JSLint also asked me to move some of my variable declarations to the top of the function. I've watched some of Doug Crockford's videos on the web where he explains that the Javascript interpreters actually hoist the declarations to the top of the function, so that recommendation makes sense. What didn't make sense was that it didn't ask me to move ALL my variable declarations out of the blocks in my function. It seemed perfectly happy with some of them.

      Initially I was getting messages like this:

      Error:

      Problem at line 17 character 22: Move 'var' declarations to the top of the function.

      for (var i = 0; i < cookiesArray.length; i++) {

      Problem at line 17 character 22: Stopping. (15% scanned).


      Unused variable: j 9 setSubKeyValue, blnUpdatedSubKey 9 setSubKeyValue

      Eventually it came back with:


      Global document, setSubKeyValue

      9 setSubKeyValue(cName, kName, value)
      Variable blnUpdatedSubKey, cookiesArray, i, j, newSubKey, subkeys
      Global document

      /*members cookie, indexOf, join, length, push, split, substring
      */

      I assume that if I don't see an "Error" that JSLint likes my code?

      Thanks,
      -Eric
    • walfisch1
      ... Put that to the top of your file: /*jslint browser: true */ Or check the Assume a browser in the web mask. ... The error message says Stopping. (15%
      Message 2 of 3 , Feb 3, 2011
      • 0 Attachment
        >> Are there any settings that will allow you do analyze JavaScript outside of an HTML document? What would you do if, for instance, you had a standalone .js file you wanted to analyze?

        Put that to the top of your file:
        /*jslint browser: true */
        Or check the "Assume a browser" in the web mask.


        >> What didn't make sense was that it didn't ask me to move ALL my variable declarations out of the blocks in my function. It seemed perfectly happy with some of them.

        The error message says "Stopping. (15% scanned)"
        The rest of your declarations are in the rest 85% I guess.








        --- In jslint_com@yahoogroups.com, "Eric" <eric.goforth@...> wrote:
        >
        > Hello,
        >
        > I have a function that I've written that's not behaving as expecting. I ran JSLint on it, it didn't really fix my problem, but I had a few questions about it's recommendations.
        >
        > The first thing I noticed was that JSLint didn't want to just analyze my function, I had to put in the tags in the text that it analyzed to make it a legitimate HTML document. Are there any settings that will allow you do analyze JavaScript outside of an HTML document? What would you do if, for instance, you had a standalone .js file you wanted to analyze?
        >
        > JSLint also asked me to move some of my variable declarations to the top of the function. I've watched some of Doug Crockford's videos on the web where he explains that the Javascript interpreters actually hoist the declarations to the top of the function, so that recommendation makes sense. What didn't make sense was that it didn't ask me to move ALL my variable declarations out of the blocks in my function. It seemed perfectly happy with some of them.
        >
        > Initially I was getting messages like this:
        >
        > Error:
        >
        > Problem at line 17 character 22: Move 'var' declarations to the top of the function.
        >
        > for (var i = 0; i < cookiesArray.length; i++) {
        >
        > Problem at line 17 character 22: Stopping. (15% scanned).
        >
        >
        > Unused variable: j 9 setSubKeyValue, blnUpdatedSubKey 9 setSubKeyValue
        >
        > Eventually it came back with:
        >
        >
        > Global document, setSubKeyValue
        >
        > 9 setSubKeyValue(cName, kName, value)
        > Variable blnUpdatedSubKey, cookiesArray, i, j, newSubKey, subkeys
        > Global document
        >
        > /*members cookie, indexOf, join, length, push, split, substring
        > */
        >
        > I assume that if I don't see an "Error" that JSLint likes my code?
        >
        > Thanks,
        > -Eric
        >
      • Eric
        Thanks, Maybe my text formating wasn t making things clear. I m now seeing: Global document, setSubKeyValue 5 setSubKeyValue(cName, kName, value) Variable
        Message 3 of 3 , Feb 3, 2011
        • 0 Attachment
          Thanks,

          Maybe my text formating wasn't making things clear. I'm now seeing:

          Global document, setSubKeyValue

          5 setSubKeyValue(cName, kName, value)
          Variable blnUpdatedSubKey, cookiesArray, i, j, newSubKey, subkeys
          Global document

          /*members cookie, indexOf, join, length, push, split, substring
          */

          I assume that's the type of response you get back from JSLint when it finds your code acceptable? I'm getting this response even though I still have a few variable declarations inside blocks in my function.

          Thanks,
          -Eric

          --- In jslint_com@yahoogroups.com, "walfisch1" <christian.wirkus@...> wrote:
          >
          > >> Are there any settings that will allow you do analyze JavaScript outside of an HTML document? What would you do if, for instance, you had a standalone .js file you wanted to analyze?
          >
          > Put that to the top of your file:
          > /*jslint browser: true */
          > Or check the "Assume a browser" in the web mask.
          >
          >
          > >> What didn't make sense was that it didn't ask me to move ALL my variable declarations out of the blocks in my function. It seemed perfectly happy with some of them.
          >
          > The error message says "Stopping. (15% scanned)"
          > The rest of your declarations are in the rest 85% I guess.
          >
          >
          >
          >
          >
          >
          >
          >
          > --- In jslint_com@yahoogroups.com, "Eric" <eric.goforth@> wrote:
          > >
          > > Hello,
          > >
          > > I have a function that I've written that's not behaving as expecting. I ran JSLint on it, it didn't really fix my problem, but I had a few questions about it's recommendations.
          > >
          > > The first thing I noticed was that JSLint didn't want to just analyze my function, I had to put in the tags in the text that it analyzed to make it a legitimate HTML document. Are there any settings that will allow you do analyze JavaScript outside of an HTML document? What would you do if, for instance, you had a standalone .js file you wanted to analyze?
          > >
          > > JSLint also asked me to move some of my variable declarations to the top of the function. I've watched some of Doug Crockford's videos on the web where he explains that the Javascript interpreters actually hoist the declarations to the top of the function, so that recommendation makes sense. What didn't make sense was that it didn't ask me to move ALL my variable declarations out of the blocks in my function. It seemed perfectly happy with some of them.
          > >
          > > Initially I was getting messages like this:
          > >
          > > Error:
          > >
          > > Problem at line 17 character 22: Move 'var' declarations to the top of the function.
          > >
          > > for (var i = 0; i < cookiesArray.length; i++) {
          > >
          > > Problem at line 17 character 22: Stopping. (15% scanned).
          > >
          > >
          > > Unused variable: j 9 setSubKeyValue, blnUpdatedSubKey 9 setSubKeyValue
          > >
          > > Eventually it came back with:
          > >
          > >
          > > Global document, setSubKeyValue
          > >
          > > 9 setSubKeyValue(cName, kName, value)
          > > Variable blnUpdatedSubKey, cookiesArray, i, j, newSubKey, subkeys
          > > Global document
          > >
          > > /*members cookie, indexOf, join, length, push, split, substring
          > > */
          > >
          > > I assume that if I don't see an "Error" that JSLint likes my code?
          > >
          > > Thanks,
          > > -Eric
          > >
          >
        Your message has been successfully submitted and would be delivered to recipients shortly.