Skip to content

Instantly share code, notes, and snippets.

Last active August 29, 2015 14:25
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save fakenickels/0243188ba81c75936eeb to your computer and use it in GitHub Desktop.
Schema for arguments, say goodbye to if's crazyness
ArgumentsSchema = function(args, schema, extra){
var orderedArgs = {};
for(var arg in args){
for(var field in schema){
if(args[arg].constructor === schema[field]){
orderedArgs[field] = args[arg];
return orderedArgs;
function msgNFn(){
var args = ArgumentsSchema(arguments, {msg: String, fn: Function});
msgNFn(console.log.bind(console), "hey")
msgNFn("hey", console.log.bind(console));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment