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

Re: (functions)

Expand Messages
  • crlender
    ... I agree about the first bad example, but I see a lot more people using the second form rather than the third, and I personally also find it much clearer.
    Message 1 of 7 , Mar 23, 2009
    • 0 Attachment
      --- In jslint_com@yahoogroups.com, "Douglas Crockford" <douglas@...> wrote:
      > 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

      I agree about the first "bad" example, but I see a lot more people
      using the second form rather than the third, and I personally also
      find it much clearer. IMO, the important thing is that there is a
      starting parenthesis before the "function" keyword, to disambiguate
      the assignment of an anonymous function reference from the case
      where a function only exists to introduce different scope.

      Please don't disallow the second form; that would prevent a lot of
      well-written scripts from passing the next version of JSLint, just
      because they use a different style to indicate the introduction of
      a new scope.


      Conrad
    • santini.alberto
      ... disallow option and funcblock option. Regards, Alberto
      Message 2 of 7 , Mar 23, 2009
      • 0 Attachment
        --- In jslint_com@yahoogroups.com, "Douglas Crockford" <douglas@...> wrote:

        > 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?
        >

        disallow option and "funcblock" option.

        Regards,
        Alberto
      • Merlin
        ... Should it be a tolerate option or a disallow option, and what should the option be called? ... Suggest Disallow bad (immediate) invocation . Preference
        Message 3 of 7 , Mar 24, 2009
        • 0 Attachment
          --- 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.

          Should it be a tolerate option or a disallow option, and what should the option be called?
          >

          Suggest "Disallow bad (immediate) invocation". Preference "badcall" ?
        • dom@happygiraffe.net
          ... badfunk ? :) -Dom
          Message 4 of 7 , Mar 24, 2009
          • 0 Attachment
            On Tue, Mar 24, 2009 at 05:28:23AM -0000, santini.alberto wrote:
            > --- In jslint_com@yahoogroups.com, "Douglas Crockford" <douglas@...> wrote:
            >
            > > 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?
            > >
            >
            > disallow option and "funcblock" option.

            "badfunk"? :)

            -Dom
          • 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 5 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 6 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.