7 ms·
If you want to allow undefined to be passed as a valid non-default value for a trailing parameter, you can also use arguments.length to determine how many argum
by noonat 14y ago
If you want to allow undefined to be passed as a valid non-default value for a trailing parameter, you can also use arguments.length to determine how many arguments were explicitly specified.
var foo = function(a, b) {
if (arguments.length < 2) {
b = 'some default value';
}
// ...
};
- ajanuary 14y agoI wish jQuery's setter methods worked this way. It's too easy to accidentally turn a setter into a getter.