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

Re: [jslint] Re: Tolerate misordered definitions

Expand Messages
  • Robert Sauer-Ernst
    well var fn = function () { use strict ; fn(); }; passes without error and without options ... Von: Erik Eckhardt Am: Tue, 28 Jun 2011
    Message 1 of 10 , Jun 29, 2011
    • 0 Attachment
      well

      var fn = function () {
      "use strict";
      fn();
      };

      passes without error and without options

      --- Original Nachricht ---

      Von: Erik Eckhardt <erik@...>
      Am: Tue, 28 Jun 2011 14:27:33 -0700
      Betreff: Re: [jslint] Re: Tolerate misordered definitions
      An: jslint_com@yahoogroups.com
      CC:
      > var fn = function() {
      > ___fn();
      > }
      >
    • douglascrockford
      ... I went to some trouble to specifically allow that case. I now think it was a mistake. The correct way to write a recursive function is var fn = function
      Message 2 of 10 , Jun 29, 2011
      • 0 Attachment
        --- In jslint_com@yahoogroups.com, Robert Sauer-Ernst <facebook@...> wrote:

        > var fn = function () {
        > "use strict";
        > fn();
        > };

        I went to some trouble to specifically allow that case. I now think it was a mistake. The correct way to write a recursive function is

        var fn = function fn() {

        or simply

        function fn() {
      • chriskennish
        After a bit more digging, I think I ve got the heart of it, and it s far simpler than I first imagined. The problem, as I see it, is as follows. This code:
        Message 3 of 10 , Jun 29, 2011
        • 0 Attachment
          After a bit more digging, I think I've got the heart of it, and it's far simpler than I first imagined. The problem, as I see it, is as follows. This code:

          var a = function () {
          "use strict";
          b();
          };

          Rightly generates an error:
          "Problem at line 3 character 5: 'b' was used before it was defined.
          Undefined variable: b 1 'a'"

          My confusion lay in that I assumed that this "before it was defined" error was dependent on the variable being defined later. I now realise that this wording is used even if the variable is never defined. It seems to me that we should get one error or the other, but not both: either "undefined", or "not defined yet", which could *then* be misorder-tolerated (or not) as the case may be.


          --- In jslint_com@yahoogroups.com, "chriskennish" <chris@...> wrote:
          >
          > Let's look at this another way. Without "Tolerate misordered definitions", we get the following:
          >
          > //Example 1
          > var abc = def(),
          > def = function () {};
          >
          > // Problem at line 1 character 11:
          > // 'def' was used before it was defined.
          >
          > //Example 2
          > var hij = function () {
          > klm();
          > },
          > klm = function () {};
          >
          > // Problem at line 2 character 5:
          > // 'klm' was used before it was defined.
          > // Undefined variable: klm 1 'hij'
          >
          > Why the extra "Undefined variable" error in example 2? If it was used before it was defined, it can't also be undefined, can it?
          >
          >
          > --- In jslint_com@yahoogroups.com, Erik Eckhardt <erik@> wrote:
          > >
          > > I *think* "Tolerate misordered definitions" is only for the form:
          > >
          > > var fn = function() {
          > > ___fn();
          > > }
          > >
          > > Not to actually use fn before it is declared. Perhaps someone will correct
          > > me if I am wrong.
          > >
          > > On Tue, Jun 28, 2011 at 2:14 PM, Douglas Crockford <douglas@>wrote:
          > >
          > > > **
          > > >
          > > >
          > > > --- In jslint_com@yahoogroups.com, "chriskennish" <chris@> wrote:
          > > >
          > > > > I'm not sure I understand. I realise that I can "fix" my code by changing
          > > > the order of the variable declarations, but that is not my point. My point
          > > > is that the "Tolerate misordered definitions" doesn't allow for this case.
          > > >
          > > > My point was that you should fix your code. Misordered definitions are one
          > > > thing, but you are trying to capture variables that haven't even been
          > > > defined yet. That is certainly making the program difficult to read and
          > > > understand. It is intolerable.
          > > >
          > > >
          > > >
          > >
          > >
          > > [Non-text portions of this message have been removed]
          > >
          >
        • Luke Page
          It would be useful to have 2 error messages if possible.. or at least change wording as I ve seen people think they can ignore it because it isn t a more harsh
          Message 4 of 10 , Jun 29, 2011
          • 0 Attachment
            It would be useful to have 2 error messages if possible.. or at least change
            wording as I've seen people think they can ignore it because it isn't a more
            harsh variable undefined...
            On 29 Jun 2011 20:39, "chriskennish" <chris@...> wrote:
            > After a bit more digging, I think I've got the heart of it, and it's far
            simpler than I first imagined. The problem, as I see it, is as follows. This
            code:
            >
            > var a = function () {
            > "use strict";
            > b();
            > };
            >
            > Rightly generates an error:
            > "Problem at line 3 character 5: 'b' was used before it was defined.
            > Undefined variable: b 1 'a'"
            >
            > My confusion lay in that I assumed that this "before it was defined" error
            was dependent on the variable being defined later. I now realise that this
            wording is used even if the variable is never defined. It seems to me that
            we should get one error or the other, but not both: either "undefined", or
            "not defined yet", which could *then* be misorder-tolerated (or not) as the
            case may be.
            >
            >
            > --- In jslint_com@yahoogroups.com, "chriskennish" <chris@...> wrote:
            >>
            >> Let's look at this another way. Without "Tolerate misordered
            definitions", we get the following:
            >>
            >> //Example 1
            >> var abc = def(),
            >> def = function () {};
            >>
            >> // Problem at line 1 character 11:
            >> // 'def' was used before it was defined.
            >>
            >> //Example 2
            >> var hij = function () {
            >> klm();
            >> },
            >> klm = function () {};
            >>
            >> // Problem at line 2 character 5:
            >> // 'klm' was used before it was defined.
            >> // Undefined variable: klm 1 'hij'
            >>
            >> Why the extra "Undefined variable" error in example 2? If it was used
            before it was defined, it can't also be undefined, can it?
            >>
            >>
            >> --- In jslint_com@yahoogroups.com, Erik Eckhardt <erik@> wrote:
            >> >
            >> > I *think* "Tolerate misordered definitions" is only for the form:
            >> >
            >> > var fn = function() {
            >> > ___fn();
            >> > }
            >> >
            >> > Not to actually use fn before it is declared. Perhaps someone will
            correct
            >> > me if I am wrong.
            >> >
            >> > On Tue, Jun 28, 2011 at 2:14 PM, Douglas Crockford <douglas@>wrote:
            >> >
            >> > > **
            >> > >
            >> > >
            >> > > --- In jslint_com@yahoogroups.com, "chriskennish" <chris@> wrote:
            >> > >
            >> > > > I'm not sure I understand. I realise that I can "fix" my code by
            changing
            >> > > the order of the variable declarations, but that is not my point. My
            point
            >> > > is that the "Tolerate misordered definitions" doesn't allow for this
            case.
            >> > >
            >> > > My point was that you should fix your code. Misordered definitions
            are one
            >> > > thing, but you are trying to capture variables that haven't even been
            >> > > defined yet. That is certainly making the program difficult to read
            and
            >> > > understand. It is intolerable.
            >> > >
            >> > >
            >> > >
            >> >
            >> >
            >> > [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.