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

Re: Circular Function Definitions

Expand Messages
  • 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 1 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 2 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 3 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.