Created
August 8, 2011 14:40
-
-
Save ritch/1131874 to your computer and use it in GitHub Desktop.
Last argument is a callback
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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