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

1262Re: [jslint] Re: option.es5

Expand Messages
  • Michael Mikowski
    Apr 6, 2010
    • 0 Attachment
      There is a very good reason to allow for trailing commas (even though IE js doesn't) -- Consider this 'object' (since we only use it as an associative array here, we call it a hash):

      var hash_example = [
      foo : 'bar',
      zing : 'zang',
      one : 'two'
      ];

      Now lets say I want to reorder the keys so they are alphabetical:

      var hash_example = [
      foo : 'bar',
      one : 'two'
      zing : 'zang',
      ];

      Boom. Instant error -- in two places. Allowing trailing commas avoids this problem nicely.

      In Perl, a trailing comma is best practice, and omitting the trailing comma is
      considered sloppy.

      If IE would allow trailing commas, I'd use them consistently. Since it doesn't, I use jslint to find the above errors :)



      Cheers, Mike



      ________________________________
      From: boyopeg <boyopeg@...>
      To: jslint_com@yahoogroups.com
      Sent: Tue, April 6, 2010 9:47:41 AM
      Subject: [jslint] Re: option.es5


      It seems to me that the trailing comma in object notation is a rather bad coding practice. I'm fine with JS parsers being able to ignore errors such as these. But why should a style and syntax checking tool like JSLint be blind to such sloppy code practices? Am I missing something with this option?

      -noah

      --- In jslint_com@yahoogro ups.com, "Douglas Crockford" <douglas@... > wrote:
      >
      > --- In jslint_com@yahoogro ups.com, "Douglas Crockford" <douglas@> wrote:
      > >
      > > There is a new option, Tolerate ES5 syntax. If you check this option, JSLint will accept the new get/set syntax in object literals.
      > >
      > > It will require that the get and set functions be declared together, that the get function have no parameters, and that the set function will have a single parameter called 'value'.
      > >
      > > Please let me know if you find any problems.
      >
      >
      > option.es5 will now relax the reserved word restriction on object
      > literals and dot notation, and tolerate a dangling comma, so
      >
      > var object = {
      > class: x.class,
      > };
      >
      > is accepted.
      >




      [Non-text portions of this message have been removed]
    • Show all 12 messages in this topic