109
rated 0 times
[
113]
[
4]
/ answers: 1 / hits: 40995
/ 13 Years ago, wed, march 7, 2012, 12:00:00
// opt_options is optional
function foo(a, b, opt_options) {
// opt_c, opt_d, and opt_e are read from 'opt_options', only c and d have defaults
var opt_c = 'default_for_c';
var opt_d = 'default_for_d';
var opt_e; // e has no default
if (opt_options) {
opt_c = opt_options.c || opt_c;
opt_d = opt_options.d || opt_d;
opt_e = opt_options.e;
}
}
The above seems awfully verbose. What's a better way to handle argument options with default parameters?
More From » design-patterns