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

jslint alternative to (function(){...}).call({})

Expand Messages
  • marcos.zanona
    I would like to use the following statement so `this` is not DOMWindow anymore, although JSLint doesn t expect so see a `.`[dot] after (function(){...}) ...
    Message 1 of 2 , Mar 26, 2012
    • 0 Attachment
      I would like to use the following statement so `this` is not DOMWindow anymore, although JSLint doesn't expect so see a `.`[dot] after (function(){...})
      ---
      (function () {
      //`this` is now {} and now DOMWindow
      }).call({});
      ---
      Is this a bad a approach, (why) ?
      Also is there any good alternative to declare this?

      Thanks a lot
    • douglascrockford
      ... I see no value in using this in that position. Try the following instead. It is slightly smaller and faster. (function (that) { // `that` is now {} }({}));
      Message 2 of 2 , Mar 26, 2012
      • 0 Attachment
        --- In jslint_com@yahoogroups.com, "marcos.zanona" <marcos@...> wrote:

        > I would like to use the following statement so `this` is not DOMWindow anymore, although JSLint doesn't expect so see a `.`[dot] after (function(){...})
        > ---
        > (function () {
        > //`this` is now {} and now DOMWindow
        > }).call({});
        > ---
        > Is this a bad a approach, (why) ?
        > Also is there any good alternative to declare this?

        I see no value in using this in that position. Try the following instead. It is slightly smaller and faster.

        (function (that) {
        // `that` is now {}
        }({}));
      Your message has been successfully submitted and would be delivered to recipients shortly.