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

Re: [jslint] Re: has not been fully defined yet

Expand Messages
  • Satyam
    I would like to add that while undefined means I don t have a clue what the value might be , null means I know it has no value (a known unknown :-P ).
    Message 1 of 24 , Mar 10, 2011
    • 0 Attachment
      I would like to add that while undefined means "I don't have a clue what
      the value might be", null means "I know it has no value" (a known
      unknown :-P ). Beyond a certain point in the application, undefined
      might mean there is an error, null means I know it has no value.

      If more languages had null and undefined we wouldn't have silly
      conventions like indexOf returning -1 when an item was not found. In
      JavaScript it is an unfortunate legacy of other languages. Ideally, you
      could have:

      var position = 'abc'.indexOf('a') sets position to 0
      var position = 'abc'.indexOf('x') should set position to null, not -1
      var position = null.indexOf('a') should leave position undefined
      (assuming the error was not caught)

      All those (0, null and undefined) are falsy but they are far from
      meaning the same. The last one shows why I said that a variable set to
      undefined might signal an error when found beyond a certain point.

      In the second case, returning false would also be an arbitrary
      convention, just as -1 is. It might be agreed that false means 'it is
      not there' but indexOf asks for the position of the item sought, not if
      it is there (where false would be a logical reply) and if it is not
      there, it has no position, no such thing, thus null, not false. Anyway,
      this is beyond the point.

      Satyam


      El 10/03/2011 17:53, abyssoft@... escribió:
      >
      > In response to the last question,
      >
      > **********
      > --- In jslint_com@yahoogroups.com
      > <mailto:jslint_com%40yahoogroups.com>, John Hawkinson <jhawk@...> wrote:
      > > Actually, you proposed:
      > >
      > > var foo = null;
      > > foo = bar(function() { if (foo) { foo.m(); } }); // Case 5
      > >
      > > but why bother to initialize foo to null? The truthiness of null and
      > > and undefined is the same...
      > **********
      >
      > The Truthiness of null and undefined are not the same.
      > while null == undefined is true, null === undefined is false; if the
      > Truthiness was the same then null === undefined would be true.
      > Also the intent of null and undefined are different in nature. When a
      > variable is declared it is by definition is undefined. Which is to say
      > it is not empty, but rather that it has yet to be defined. Null is a
      > empty state, think of Null in terms of math with help with this
      > concept as null is also known as the empty set. Undefined in math
      > terms and null (empty) in math terms are not equivalent (undefined !==
      > null) but they are similar (undefined == null).
      >
      > Declare but leave uninitialized
      >
      > var someVariable1; // assignment to undefined is understood
      > var someVariable2 = undefined; // does the same as example 1 but will
      > throw lint warning, use example 1
      >
      > someVariable1 = 123; // assign value to variable
      > someVariable1 = undefined; // destruct variable but leave declared
      >
      > Declare and initialize to empty
      > var someVariable3 = null;
      > someVariable1 = 123; // assign value to variable
      > someVariable1 = null; // empty variable
      >
      > Hope this short post clears up confusion between undefined and null.
      >
      >
      > ------------------------------------------------------------------------
      >
      > No virus found in this message.
      > Checked by AVG - www.avg.com <http://www.avg.com>
      > Version: 10.0.1204 / Virus Database: 1497/3495 - Release Date: 03/09/11
      >


      [Non-text portions of this message have been removed]
    • Lindsay John Lawrence
      Hello,       Problem at line 9 character 7: Unexpected continue . I now get an error like the above with loops that have a continue of the form shown
      Message 2 of 24 , Mar 10, 2011
      • 0 Attachment
        Hello,

              Problem at line 9 character 7: Unexpected 'continue'.


        I now get an error like the above with loops that have a 'continue' of the form shown in the sample code below.

        Is this a bug in jslint or is it now enforcing some form I am not aware of?

        // --- start sample code ---
        var nop = function () {
          return;
        };

        var test = function () {
          var i;
          for (i=0; i<10; i+=1) {
            if (i<5) {
              continue;
            }
            nop();
          }
        };
        // --- end sample code ---

        Thanks in advancet,

        Lindsay





        [Non-text portions of this message have been removed]
      • spence.randall@ymail.com
        It s not a bug, JSLint has a new(ish) Tolerate continue option. You can check that box in options, or add /*jslint continue:true*/ to your code. Or you could
        Message 3 of 24 , Mar 10, 2011
        • 0 Attachment
          It's not a bug, JSLint has a new(ish) "Tolerate continue" option. You can check that box in options, or add /*jslint continue:true*/ to your code.

          Or you could refactor your code to avoid the use of continue. In your example, you could just set i = 5 in the loop and drop the if check, or check if i > 5 then run nop().

          -Randall

          --- In jslint_com@yahoogroups.com, Lindsay John Lawrence <thinknlive@...> wrote:
          >
          > Hello,
          >
          >       Problem at line 9 character 7: Unexpected 'continue'.
          >
          >
          > I now get an error like the above with loops that have a 'continue' of the form shown in the sample code below.
          >
          > Is this a bug in jslint or is it now enforcing some form I am not aware of?
          >
          > // --- start sample code ---
          > var nop = function () {
          >   return;
          > };
          >
          > var test = function () {
          >   var i;
          >   for (i=0; i<10; i+=1) {
          >     if (i<5) {
          >       continue;
          >     }
          >     nop();
          >   }
          > };
          > // --- end sample code ---
          >
          > Thanks in advancet,
          >
          > Lindsay
          >
          >
          >
          >
          >
          > [Non-text portions of this message have been removed]
          >
        • Lindsay John Lawrence
          Thanks! Why the change though? Is continue being deprecated in the language? --Lindsay ... From: spence.randall@ymail.com Subject:
          Message 4 of 24 , Mar 10, 2011
          • 0 Attachment
            Thanks! Why the change though? Is 'continue' being deprecated in the language?

            --Lindsay


            --- On Thu, 3/10/11, spence.randall@... <randall@...> wrote:

            From: spence.randall@... <randall@...>
            Subject: [jslint] Re: JSLint Bug?
            To: jslint_com@yahoogroups.com
            Date: Thursday, March 10, 2011, 11:00 AM







             













            It's not a bug, JSLint has a new(ish) "Tolerate continue" option. You can check that box in options, or add /*jslint continue:true*/ to your code.



            Or you could refactor your code to avoid the use of continue. In your example, you could just set i = 5 in the loop and drop the if check, or check if i > 5 then run nop().



            -Randall



            --- In jslint_com@yahoogroups.com, Lindsay John Lawrence <thinknlive@...> wrote:

            >

            > Hello,

            >

            >       Problem at line 9 character 7: Unexpected 'continue'.

            >

            >

            > I now get an error like the above with loops that have a 'continue' of the form shown in the sample code below.

            >

            > Is this a bug in jslint or is it now enforcing some form I am not aware of?

            >

            > // --- start sample code ---

            > var nop = function () {

            >   return;

            > };

            >

            > var test = function () {

            >   var i;

            >   for (i=0; i<10; i+=1) {

            >     if (i<5) {

            >       continue;

            >     }

            >     nop();

            >   }

            > };

            > // --- end sample code ---

            >

            > Thanks in advancet,

            >

            > Lindsay

            >

            >

            >

            >

            >

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

            >

























            [Non-text portions of this message have been removed]
          • spence.randall@ymail.com
            Deprecated? No, I don t think so. There are almost always better ways of writing statements that more explicitly define what you are attempting to do without
            Message 5 of 24 , Mar 10, 2011
            • 0 Attachment
              Deprecated? No, I don't think so. There are almost always better ways of writing statements that more explicitly define what you are attempting to do without resorting to continue. JSLint is all about the good parts, and not about the parts that are acceptable. It forces you to use a higher standard than the one defined.

              Douglas says it best in his book:

              "The continue statement jumps to the top of the loop. I have never seen a piece of code that was not improved by refactoring it to remove the continue statement."

              -Randall

              --- In jslint_com@yahoogroups.com, Lindsay John Lawrence <thinknlive@...> wrote:
              >
              > Thanks! Why the change though? Is 'continue' being deprecated in the language?
              >
              > --Lindsay
              >
              >
              > --- On Thu, 3/10/11, spence.randall@... <randall@...> wrote:
              >
              > From: spence.randall@... <randall@...>
              > Subject: [jslint] Re: JSLint Bug?
              > To: jslint_com@yahoogroups.com
              > Date: Thursday, March 10, 2011, 11:00 AM
              >
              >
              >
              >
              >
              >
              >
              >  
              >
              >
              >
              >
              >
              >
              >
              >
              >
              >
              >
              >
              >
              > It's not a bug, JSLint has a new(ish) "Tolerate continue" option. You can check that box in options, or add /*jslint continue:true*/ to your code.
              >
              >
              >
              > Or you could refactor your code to avoid the use of continue. In your example, you could just set i = 5 in the loop and drop the if check, or check if i > 5 then run nop().
              >
              >
              >
              > -Randall
              >
              >
              >
              > --- In jslint_com@yahoogroups.com, Lindsay John Lawrence <thinknlive@> wrote:
              >
              > >
              >
              > > Hello,
              >
              > >
              >
              > >       Problem at line 9 character 7: Unexpected 'continue'.
              >
              > >
              >
              > >
              >
              > > I now get an error like the above with loops that have a 'continue' of the form shown in the sample code below.
              >
              > >
              >
              > > Is this a bug in jslint or is it now enforcing some form I am not aware of?
              >
              > >
              >
              > > // --- start sample code ---
              >
              > > var nop = function () {
              >
              > >   return;
              >
              > > };
              >
              > >
              >
              > > var test = function () {
              >
              > >   var i;
              >
              > >   for (i=0; i<10; i+=1) {
              >
              > >     if (i<5) {
              >
              > >       continue;
              >
              > >     }
              >
              > >     nop();
              >
              > >   }
              >
              > > };
              >
              > > // --- end sample code ---
              >
              > >
              >
              > > Thanks in advancet,
              >
              > >
              >
              > > Lindsay
              >
              > >
              >
              > >
              >
              > >
              >
              > >
              >
              > >
              >
              > > [Non-text portions of this message have been removed]
              >
              > >
              >
              >
              >
              >
              >
              >
              >
              >
              >
              >
              >
              >
              >
              >
              >
              >
              >
              >
              >
              >
              >
              >
              >
              >
              >
              > [Non-text portions of this message have been removed]
              >
            • Lindsay John Lawrence
              Thanks! I have read that book cover to cover several times and it continues to be an excellent reference... somehow I missed that statement of his though. ...
              Message 6 of 24 , Mar 10, 2011
              • 0 Attachment
                Thanks! I have read that book cover to cover several times and it continues to be an excellent reference... somehow I missed that statement of his though.

                --- On Thu, 3/10/11, spence.randall@... <randall@...> wrote:

                From: spence.randall@... <randall@...>
                Subject: [jslint] Re: JSLint Bug?
                To: jslint_com@yahoogroups.com
                Date: Thursday, March 10, 2011, 11:47 AM







                 













                Deprecated? No, I don't think so. There are almost always better ways of writing statements that more explicitly define what you are attempting to do without resorting to continue. JSLint is all about the good parts, and not about the parts that are acceptable. It forces you to use a higher standard than the one defined.



                Douglas says it best in his book:



                "The continue statement jumps to the top of the loop. I have never seen a piece of code that was not improved by refactoring it to remove the continue statement."



                -Randall



                --- In jslint_com@yahoogroups.com, Lindsay John Lawrence <thinknlive@...> wrote:

                >

                > Thanks! Why the change though? Is 'continue' being deprecated in the language?

                >

                > --Lindsay

                >

                >

                > --- On Thu, 3/10/11, spence.randall@... <randall@...> wrote:

                >

                > From: spence.randall@... <randall@...>

                > Subject: [jslint] Re: JSLint Bug?

                > To: jslint_com@yahoogroups.com

                > Date: Thursday, March 10, 2011, 11:00 AM

                >

                >

                >

                >

                >

                >

                >

                >  

                >

                >

                >

                >

                >

                >

                >

                >

                >

                >

                >

                >

                >

                > It's not a bug, JSLint has a new(ish) "Tolerate continue" option. You can check that box in options, or add /*jslint continue:true*/ to your code.

                >

                >

                >

                > Or you could refactor your code to avoid the use of continue. In your example, you could just set i = 5 in the loop and drop the if check, or check if i > 5 then run nop().

                >

                >

                >

                > -Randall

                >

                >

                >

                > --- In jslint_com@yahoogroups.com, Lindsay John Lawrence <thinknlive@> wrote:

                >

                > >

                >

                > > Hello,

                >

                > >

                >

                > >       Problem at line 9 character 7: Unexpected 'continue'.

                >

                > >

                >

                > >

                >

                > > I now get an error like the above with loops that have a 'continue' of the form shown in the sample code below.

                >

                > >

                >

                > > Is this a bug in jslint or is it now enforcing some form I am not aware of?

                >

                > >

                >

                > > // --- start sample code ---

                >

                > > var nop = function () {

                >

                > >   return;

                >

                > > };

                >

                > >

                >

                > > var test = function () {

                >

                > >   var i;

                >

                > >   for (i=0; i<10; i+=1) {

                >

                > >     if (i<5) {

                >

                > >       continue;

                >

                > >     }

                >

                > >     nop();

                >

                > >   }

                >

                > > };

                >

                > > // --- end sample code ---

                >

                > >

                >

                > > Thanks in advancet,

                >

                > >

                >

                > > Lindsay

                >

                > >

                >

                > >

                >

                > >

                >

                > >

                >

                > >

                >

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

                >

                > >

                >

                >

                >

                >

                >

                >

                >

                >

                >

                >

                >

                >

                >

                >

                >

                >

                >

                >

                >

                >

                >

                >

                >

                >

                >

                > [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.