Skip to content

Instantly share code, notes, and snippets.

@ritch
Created August 8, 2011 14:40
Show Gist options
  • Save ritch/1131874 to your computer and use it in GitHub Desktop.
Save ritch/1131874 to your computer and use it in GitHub Desktop.
Last argument is a callback
// when the last arg is a function - call it.
function test() {
var args = arguments.length
, callback = args && arguments[args - 1]
, result = callback.call && callback.call();
console.log(result);
}
test(1,2,3,4,5,6,7, function(){
console.log('The answer is 42.');
return 42;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment