Skip to content

Instantly share code, notes, and snippets.

@tonylukasavage
Created June 4, 2014 15:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tonylukasavage/926036157c4411e6a77e to your computer and use it in GitHub Desktop.
Save tonylukasavage/926036157c4411e6a77e to your computer and use it in GitHub Desktop.
maybeCallback(), slightly modified, from node.js source, for adding default callbacks if they aren't provided, with optional options
var util = require('util');
function maybeCallback(cb) {
return util.isFunction(cb) ? cb : function(err) { if (err) throw err; };
}
function iShouldHaveACallback(opts, callback) {
callback = maybeCallback(arguments[arguments.length-1]);
if (!opts || util.isFunction(opts)) {
opts = {};
}
// get down to business...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment