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

Re: "this" strict mode error

Expand Messages
  • douglascrockford
    ... The this psuedoparameter is bound to undefined (not the global object) when a function is called in the function form in strict mode. JSLint must do its
    Message 1 of 2 , Feb 28, 2012
    • 0 Attachment
      --- In jslint_com@yahoogroups.com, "firstbakingbook" <craft.brian@...> wrote:

      > I expect this is a common question, but searching for "this" isn't getting me anywhere.
      >
      > "use strict";
      >
      > function foo()
      > {
      > var a = this;
      > }
      >
      > var bar = function()
      > {
      > var a = this;
      > };
      >
      > jslint likes bar, but not foo. Why?

      The this psuedoparameter is bound to undefined (not the global object) when a function is called in the function form in strict mode. JSLint must do its tests statically, so it assumes that if you defined something as a function then you intend to call it as a function. Otherwise, it assumes that you will use it as a method.

      This is not infallible, but it is the best I can do.
    Your message has been successfully submitted and would be delivered to recipients shortly.