Skip to content

Instantly share code, notes, and snippets.

@dgmike
Last active August 29, 2015 14:04
Show Gist options
  • Select an option

  • Save dgmike/a7520ac4c71f280463f5 to your computer and use it in GitHub Desktop.

Select an option

Save dgmike/a7520ac4c71f280463f5 to your computer and use it in GitHub Desktop.
js: passing optional arguments
var cb, republish;
republish = function(message, update, queue, callback) {
if (typeof update === "function") {
callback = update;
queue = update || queue;
update = void 0;
}
if (typeof queue === "function") {
callback = callback || queue;
queue = void 0;
}
return {
message: message,
update: update,
queue: queue,
callback: callback
};
};
cb = function() {};
console.clear();
console.table({
one: republish('msg'),
two: republish('msg', cb),
three: republish('msg', {}, cb),
four: republish('msg', {}, 'queue', cb)
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment