tcoulter / jockeyjs

Library to facilitate communication between iOS apps and JS apps running inside a UIWebView
MIT License
458 stars 99 forks source link

Use f.length instead of returning false? #5

Closed andrewschaaf closed 11 years ago

andrewschaaf commented 11 years ago

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 commented 11 years ago

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.