Skip to content

Instantly share code, notes, and snippets.

@angus-c
Forked from abozhilov/gist:1333507
Created November 2, 2011 16:28
Show Gist options
  • Save angus-c/1334100 to your computer and use it in GitHub Desktop.
Save angus-c/1334100 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