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

1717Re: [jslint] Circular Function Definitions

Expand Messages
  • Erik Eckhardt
    Jan 3, 2011
    • 0 Attachment
      My apologies. My code was written too hastily. I thought you were using a
      Boolean to indicate whether to make the return call to f.

      The point I was trying to get across is that you don't need the circularity.

      There are many ways to solve this. Here's one: Any time you want something
      to happen after the callback, pass the call to the callback in an anonymous
      function:

      f = function() {
      ___// do stuff
      ___xhr(params, callback); // plain call to cb func
      ___xhr(params, function() {callback(); f();}); // circular call back to f
      }

      Or pass the after-callback function as a parameter to the callback function
      (again through use of an anonymous function).

      or: `callback.returnfn = f; // now check property in that function and call
      if needed

      Or use a library like jquery and define a custom event, then bind all the
      handlers to the event you want, and trigger it any time.

      Circularity isn't required.

      Erik

      On Fri, Dec 31, 2010 at 12:12 PM, Felix E. Klee <felix.klee@...> wrote:

      >
      >
      > On Fri, Dec 31, 2010 at 7:21 PM, Erik Eckhardt <erik@...<erik%40eckhardts.com>>
      > wrote:
      > > function callback(morefn) {
      > > // do something ...
      > > if (typeof(morefn) === 'function') {
      > > moref();
      > > }
      > > }
      > >
      > > f = function () {
      > > sendToServer('xyz', callback ? f : null);
      > > };
      >
      > Are you sure this makes sense? The second last line will always evaluate
      > to:
      >
      > sendToServer('xyz', f);
      >
      > And I don't see how this solves the issue I raised:
      >
      > var f;
      >
      > function callback(moreToDo) {
      > // ...
      > }
      >
      > f = function () {
      > // ...
      > };
      >
      > That's inconsistent, and thus confusing. Of course one could write:
      >
      > var callback, f;
      >
      > callback = function (moreToDo) {
      > // ...
      > };
      >
      > f = function () {
      > // ...
      > };
      >
      > Now things are consistent. But is that the way to go?
      >
      >


      [Non-text portions of this message have been removed]
    • Show all 17 messages in this topic