-
-
Save angus-c/1334100 to your computer and use it in GitHub Desktop.
Arguments default value (allow empty args)
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
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