Created
July 25, 2013 19:44
-
-
Save skypanther/6083082 to your computer and use it in GitHub Desktop.
Within functions, arguments gives access to any parameters passed to the function. But it's a funky object, not a true array. I'm sure the following behavior is documented, but it caught me off-guard. So I thought I'd share.
This file contains 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
var myFunction = function() { | |
if(typeof arguments[0] == 'function') { | |
arguments[0](); // throws error: [object Object] is not a function | |
// but this works | |
var cb = arguments[0]; | |
cb(); | |
} | |
}; | |
myFunction(function() { | |
// do something | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment