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

Re: [jslint] Re: Circular Function Definitions

Expand Messages
  • Felix E. Klee
    ... The question is: Why? Is that considered bad practice? If so, a reference please. ... See my original post. There I mentioned that I would like to enforce
    Message 1 of 17 , Jan 6, 2011
    • 0 Attachment
      On Thu, Jan 6, 2011 at 6:27 AM, Jordan <ljharb@...> wrote:
      > I think the confusion here is that you shouldn't be using the
      > "circular function" pattern you are using.

      The question is: Why? Is that considered bad practice? If so, a
      reference please.

      > In addition, you are using function declarations rather than assigning
      > a function statement to a variable.

      See my original post. There I mentioned that I would like to enforce
      that convention for the whole project using JSLint. Only I wonder why
      there is no such option.

      > What I can think of off the top of my head is:
      >
      > [...]
      > requestCommentary = function () {
      > return onCommentaryReceived(null, true);
      > };

      That would work, but it's confusing to read. At least the function name
      "onCommentaryReceived" should be changed.

      > Alternatively, and with less refactoring:

      See my original post. It's there already.
    • Felix E. Klee
      On Fri, Dec 31, 2010 at 6:33 PM, Felix E. Klee ... Just figured that this is akin to: http://en.wikipedia.org/wiki/Mutual_recursion And I
      Message 2 of 17 , Jan 8, 2011
      • 0 Attachment
        On Fri, Dec 31, 2010 at 6:33 PM, Felix E. Klee <felix.klee@...>
        wrote:
        > If I write code such as the following

        Just figured that this is akin to:

        http://en.wikipedia.org/wiki/Mutual_recursion

        And I checked: The latest version of JSLint, 2011-01-06, still
        complains about an undefined function.
      • Douglas Crockford
        ... ` var sendToServer; ` ` function f() { ` sendToServer( xyz , function (moreToDo) { ` // do something ... ` if (moreToDo) { `
        Message 3 of 17 , Jan 8, 2011
        • 0 Attachment
          --- In jslint_com@yahoogroups.com, "Felix E. Klee" <felix.klee@...> wrote:
          >
          > If I write code such as the following, then JSLint complains that "f" is
          > not defined.
          >
          > var sendToServer;
          >
          > function callback(moreToDo) {
          > // do something ...
          > if (moreToDo) {
          > f();
          > }
          > }
          >
          > function f() {
          > sendToServer('xyz', callback);
          > }
          >
          > What's the most elegant solution to get rid of the error message?


          ` var sendToServer;
          `
          ` function f() {
          ` sendToServer('xyz', function (moreToDo) {
          ` // do something ...
          ` if (moreToDo) {
          ` f();
          ` }
          ` });
          ` }
        • Felix E. Klee
          On Sat, Jan 8, 2011 at 4:05 PM, Douglas Crockford ... Thanks for the suggestion! I guess I ll take this approach and put the lengthy do something into a
          Message 4 of 17 , Jan 8, 2011
          • 0 Attachment
            On Sat, Jan 8, 2011 at 4:05 PM, Douglas Crockford
            <douglas@...> wrote:
            > ` var sendToServer;
            > `
            > ` function f() {
            > ` sendToServer('xyz', function (moreToDo) {
            > ` // do something ...
            > ` if (moreToDo) {
            > ` f();
            > ` }
            > ` });
            > ` }

            Thanks for the suggestion! I guess I'll take this approach and put the
            lengthy "do something" into a separate function.

            Just thinking about it: I assume that having JSLint to *not* report an
            error on circular function definitions is non-trivial. That is, if one
            still wants to be warned about cases were an undefined function would be
            called, such as:

            function f() {
            g();
            }

            f();

            function g() {
            // do something
            }
          Your message has been successfully submitted and would be delivered to recipients shortly.