Created
May 16, 2015 12:25
-
-
Save ducin/5e2bf652be6556b1069f to your computer and use it in GitHub Desktop.
map positional arguments into options object
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
"use strict"; | |
// run `npm install introspect` before | |
var introspect = require('introspect'); | |
function generateEmail(firstName, lastName, provider) { | |
return firstName + "." + lastName + "@" + provider; | |
} | |
var argMapify = function(fn, argValues, context) { | |
var argDefs = introspect(fn); | |
return fn.apply(context, argDefs.map(function(arg) { | |
return argValues[arg]; | |
})); | |
} | |
console.log(introspect(generateEmail)); | |
console.log(argMapify(generateEmail, {firstName: "John", lastName: "Smith", "provider": "gmail.com"})); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment