Skip to content

Instantly share code, notes, and snippets.

@nasser
Last active August 29, 2015 14:01
Show Gist options
  • Save nasser/dbe32a106edf7deb9a8d to your computer and use it in GitHub Desktop.
Save nasser/dbe32a106edf7deb9a8d to your computer and use it in GitHub Desktop.
function namedArgs(fn) {
var names = fn.toString().match(/function.*\(([^\)]+)\)/)[1].split(',');
return eval("(function(args) {\
return fn(" + names.map(function(n) { return "args[\"" + n.trim() + "\"]"}).join() + ");\
})");
}
@OmerShapira
Copy link

Wow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment