Skip to content

Instantly share code, notes, and snippets.

@skypanther
Created July 25, 2013 19:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save skypanther/6083082 to your computer and use it in GitHub Desktop.
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.
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