Skip to content

Instantly share code, notes, and snippets.

@ducin
Created May 16, 2015 12:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ducin/5e2bf652be6556b1069f to your computer and use it in GitHub Desktop.
Save ducin/5e2bf652be6556b1069f to your computer and use it in GitHub Desktop.
map positional arguments into options object
"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