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

414RE: [jslint] (functions)

Expand Messages
  • m m
    Mar 24, 2009
    • 0 Attachment
      disallow: Wrapped immd function literals? -----Original Message-----
      Date: Monday, March 23, 2009 7:45:26 pm
      To: jslint_com@yahoogroups.com
      From: "Douglas Crockford" <douglas@...>
      Subject: [jslint] (functions)

      I have seen a lot of confusion around use of immediate invocation of functions. I think JSLint can help if we can insist on some specific styling.

      I am proposing that when a function literal is to be called immediately, then the whole expression be wrapped in parens. So

      var foo = function () {}(); // bad
      var foo = (function () {})(); // bad
      var foo = (function () {}()); // good

      Also, a function cannot be placed alone in parens.

      var foo = (function () {}); // bad
      var foo = function () {}; // good

      There is a lot of code that is unaware of this style, so I need an option to control it. Should it be a tolerate option or a disallow option, and what should the option be called?
    • Show all 7 messages in this topic