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

RE: [jslint] (functions)

Expand Messages
  • m m
    disallow: Wrapped immd function literals? -----Original Message----- Date: Monday, March 23, 2009 7:45:26 pm To: jslint_com@yahoogroups.com From: Douglas
    Message 1 of 7 , 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?
    • Frederick Staats
      Most code that I work with is of the following form which I would not like to have called bad : var foo = (function () {})(); In reality this code really
      Message 2 of 7 , Mar 24, 2009
      • 0 Attachment
        Most code that I work with is of the following form which I would not like to have called "bad":
        var foo = (function () {})();

        In reality this code really looks like:

        var foo = (funciton () {
        // Somethign interesting here;
        })();

        Which looks similar to how passed functions look:
        myfunc(function () {



        I can not recall ever seeing the following form. I think is harder to read and do not believe it is in as common use.
        var foo = (function () {}());

        I don't really think we are solving a big problem by giving styling guidelines here.

        --
        Frederick (Fritz) Staats

        --- In jslint_com@yahoogroups.com, "Douglas Crockford" <douglas@...> wrote:
        >
        > 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?
        >
      Your message has been successfully submitted and would be delivered to recipients shortly.