Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use f.length instead of returning false? #5

Closed
andrewschaaf opened this issue Mar 5, 2013 · 1 comment
Closed

Use f.length instead of returning false? #5

andrewschaaf opened this issue Mar 5, 2013 · 1 comment

Comments

@andrewschaaf
Copy link
Contributor

Example from the README:

Jockey.on("event-name", function(payload, complete) {
  setTimeout(function() { complete(); }, 1000);

  // Note: You MUST return false in this case to tell Jockey you plan on calling
  // the complete function on your own once events have finished.
  return false;
});

The return false hassle can be avoided.

The Jockey code that calls this function literal can detect how many arguments it has (simply f.length).

You could have function(payload){} be treated as sync and function(payload, complete){} be treated as async.

Mocha uses this. (See its documentation's Sync and Async sections)

@tcoulter
Copy link
Owner

tcoulter commented Mar 5, 2013

So I learned something. Mozilla's version of what you just said: https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Function/length

Awesome, will change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants