Skip to content

Instantly share code, notes, and snippets.

@rafbm
Forked from angus-c/gist:1334100
Created November 2, 2011 17:02
Show Gist options
  • Save rafbm/1334218 to your computer and use it in GitHub Desktop.
Save rafbm/1334218 to your computer and use it in GitHub Desktop.
Arguments default value (allow empty args)
function func(a, f) {
return function(args) {
args = args || {};
args.__proto__ = a;
f.call(this, args);
};
};
var f = func({ foo: 10, bar: 20 }, function(args) {
console.log(args.foo, args.bar);
});
f(); // 10 20
f({ foo: 50 }); // 50 20
f({ foo: 50, bar: 50 }); // 50 50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment