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

[jslint] Re: explanations for some options

Expand Messages
  • pauanyu
    P.S. ECMAScript 5 actually isn t supported in browsers right now, so the JSLint option is more about future-proofing your code. That way, when browsers finally
    Message 1 of 6 , Jul 20, 2010
    • 0 Attachment
      P.S. ECMAScript 5 actually isn't supported in browsers right now, so the JSLint option is more about future-proofing your code.

      That way, when browsers finally do support ECMAScript 5, your code will reap the benefits of strict mode.

      Some benefits of ECMAScript 5 strict mode:

      typeof [] returns "array" rather than "object"
      typeof null returns "null" rather than "object"

      If you forget to use "new" when using a constructor, like new Foobar(), it will throw an error. Before, it would silently attach the constructor's properties to the global object (usually window).

      Dangling commas are allowed in object literals now. For instance, like this:

      {
      foo: "hello",
      bar: "world",
      }

      There are no more implied global variables. You must now define variables using the "var" keyword. Before, if you tried to assign to a variable that didn't exist, it would implicitly create a global variable.

      The special "this" variable correctly propagates within inner functions. For instance, this code will run correctly:

      var foo = {
      message: "Hello world",
      saySomething: function () {
      return (function () {
      return this.message;
      }());
      }
      };

      foo.saySomething() returns "Hello world". In previous ECMAScript versions, it would return "undefined", because the meaning of "this" is bound to the global object while within inner functions.

      --- In jslint_com@yahoogroups.com, Mark Volkmann <r.mark.volkmann@...> wrote:
      >
      > Thank you very much! That's exactly the kind of explanation I was hoping
      > for.
      >
      > I have to say it's a little scary to thing about people writing regular
      > expressions and not knowing what "dot" means!
      >
      > On Mon, Jul 19, 2010 at 12:40 PM, pauanyu <pcxunlimited@...> wrote:
      >
      > >
      > >
      > > nomen: Some developers use a _ to mean "hidden" or "private" properties,
      > > but they are not actually hidden at all. They are visible just like all
      > > others. If you really want it to be hidden, use a local variable with a
      > > closure.
      > >
      > > regexp: The rationale behind this is that some people don't understand what
      > > . and [^...] mean in regular expressions, so it causes their code to either
      > > accept something as valid when it isn't, or reject something that's valid.
      > >
      > > strict: "use strict" turns on ECMAScript 5's strict mode. This fixes
      > > numerous flaws in JavaScript, and also causes some bad stuff to throw an
      > > error, rather than failing silently. I think it's definitely a good thing to
      > > use this whenever you can.
      > >
      > >
      > > --- In jslint_com@yahoogroups.com <jslint_com%40yahoogroups.com>, Mark
      > > Volkmann <r.mark.volkmann@> wrote:
      > > >
      > > > I'm trying to understand the rationale behind three of the "Good
      > > > Parts" options and haven't quite figured them out from the short
      > > > descriptions on the web site. Can someone give me a brief explanation
      > > > for why turning these options on is a good idea? I'm not looking to
      > > > debate them. I just want to understand the issues they avoid.
      > > >
      > > > nomen
      > > > regexp
      > > > strict
      > > >
      > > > --
      > > > R. Mark Volkmann
      > > > Object Computing, Inc.
      > > >
      > >
      > >
      > >
      >
      >
      >
      > --
      > R. Mark Volkmann
      > Object Computing, Inc.
      >
      >
      > [Non-text portions of this message have been removed]
      >
    • Douglas Crockford
      ... Not true. typeof remains broken. An Array.isArray method is added. ... Not exactly. this will be bound to undefined, which might result in throwing. ...
      Message 2 of 6 , Jul 21, 2010
      • 0 Attachment
        --- In jslint_com@yahoogroups.com, "pauanyu" <pcxunlimited@...> wrote:

        > Some benefits of ECMAScript 5 strict mode:
        >
        > typeof [] returns "array" rather than "object"
        > typeof null returns "null" rather than "object"

        Not true. typeof remains broken. An Array.isArray method is added.

        > If you forget to use "new" when using a constructor, like new Foobar(), it will throw an error. Before, it would silently attach the constructor's properties to the global object (usually window).

        Not exactly. this will be bound to undefined, which might result in throwing.


        > The special "this" variable correctly propagates within inner functions. For instance, this code will run correctly:
        >
        > var foo = {
        > message: "Hello world",
        > saySomething: function () {
        > return (function () {
        > return this.message;
        > }());
        > }
        > };

        Not true. this in all inner functions is undefined.
      • pauanyu
        Really! I heard talk about typeof being fixed. I guess they figured it would cause too many compatibility problems so they cut it? I also recall hearing about
        Message 3 of 6 , Jul 21, 2010
        • 0 Attachment
          Really! I heard talk about typeof being fixed. I guess they figured it would cause too many compatibility problems so they cut it?

          I also recall hearing about "this" being properly bound while within inner functions. I wonder why that was changed.

          Either way, sorry for the misinformation.

          --- In jslint_com@yahoogroups.com, "Douglas Crockford" <douglas@...> wrote:
          >
          > --- In jslint_com@yahoogroups.com, "pauanyu" <pcxunlimited@> wrote:
          >
          > > Some benefits of ECMAScript 5 strict mode:
          > >
          > > typeof [] returns "array" rather than "object"
          > > typeof null returns "null" rather than "object"
          >
          > Not true. typeof remains broken. An Array.isArray method is added.
          >
          > > If you forget to use "new" when using a constructor, like new Foobar(), it will throw an error. Before, it would silently attach the constructor's properties to the global object (usually window).
          >
          > Not exactly. this will be bound to undefined, which might result in throwing.
          >
          >
          > > The special "this" variable correctly propagates within inner functions. For instance, this code will run correctly:
          > >
          > > var foo = {
          > > message: "Hello world",
          > > saySomething: function () {
          > > return (function () {
          > > return this.message;
          > > }());
          > > }
          > > };
          >
          > Not true. this in all inner functions is undefined.
          >
        Your message has been successfully submitted and would be delivered to recipients shortly.