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

Re: [jslint] Re: Strict violation

Expand Messages
  • Michael
    ... A full explanation would really be helpful. This was something that was really confusing me just this morning. Especially with a lot of libraries which
    Message 1 of 14 , Oct 19, 2010
    • 0 Attachment
      On Tue, Oct 19, 2010 at 3:17 PM, pauanyu <pcxunlimited@...> wrote:

      >
      >
      > --- In jslint_com@yahoogroups.com <jslint_com%40yahoogroups.com>, "Douglas
      > Crockford" <douglas@...> wrote:
      > >
      > > --- In jslint_com@yahoogroups.com <jslint_com%40yahoogroups.com>,
      > "pauanyu" <pcxunlimited@> wrote:
      > >
      > > > "use strict";
      > > >
      > > > function foo() {
      > > > return this.message;
      > > > }
      > > >
      > > > document.body.addEventListener("click", foo, true);
      > > >
      > > >
      > > > The above returns the same error, at the same location. What do I need
      > to do to convince you that this is a problem? I think JSLint should tolerate
      > "this" when it is being used in these two ways.
      > > >
      > > > Both ways should be valid, according to ECMAScript 5 strict mode, so
      > unless you have a reason to believe that these two use-cases should be
      > banned...
      > >
      > >
      > > There is a lot of crappy code that ES5 accepts that JSLint rejects. Your
      > argument will not work here.
      > >
      > > The point of ES5/strict is to prohibit leaking of the global object,
      > something that ES3 does promiscuously. ES5/strict does some of its work
      > dynamically, and some of its work statically. JSLint does all of its work
      > statically, so it must be even more restrictive in order to best help you
      > get your program right. Remember that the goal of JSLint is to improve code
      > quality, not to make you feel good about sloppy work.
      > >
      > > So when JSLint sees you saying "use strict"; and then sees you use a
      > function statement containing this, it assumes that you don't know what you
      > are doing and it gives you a warning.
      > >
      > > My advice is that you either stop using strict mode, or adopt a more
      > professional coding style.
      > >
      >
      > In that case, could you at least change the error message to something
      > like:
      >
      > Strict violation: don't use "this" within a function.
      >

      A full explanation would really be helpful. This was something that was
      really confusing me just this morning. Especially with a lot of libraries
      which show examples of applying a scope to a callback function. Looking at
      it now explicit is beautiful, but as a long time JS programmer, I always
      thought the other way was better until I did research and read into some of
      Douglas's comments in this thread.

      Thanks,

      Michael


      [Non-text portions of this message have been removed]
    Your message has been successfully submitted and would be delivered to recipients shortly.