News for hackers. Stuff that matters.
Re:Default Parameters in JavaScript by masklinn on Tuesday March 19, 2013 @01:34PM (#5402332)
As with _.extend, _.defaults takes 1..n arguments and will fold 2..n into 1. If you fear callers will pass in an object they rely on for function options (doubtful, but why not) you can just write:

    var actual_opts = _.defaults({}, opts, {
        // Your defaults here
    });
where ``opts`` is the options object passed in.

This also fixes the issue of a caller passing in no options (or "null" or "undefined") without having to add an `||`

There are no comments on this comment yet.