Last active
August 29, 2015 14:01
-
-
Save nasser/dbe32a106edf7deb9a8d to your computer and use it in GitHub Desktop.
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
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() + ");\ | |
})"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Converts a javascript function using traditional positional arguments to use named arguments from an object. Argument names are taken from the original declaration.
Or from coffeescript