Hacker News new | ask | show | jobs
by noonat 4836 days 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';
        }
        // ...
    };
1 comments

I wish jQuery's setter methods worked this way. It's too easy to accidentally turn a setter into a getter.