News for hackers. Stuff that matters.
Re:Default Parameters in JavaScript by masklinn on Tuesday March 19, 2013 @01:38PM (#5402356)
zimbatm notes an issue with altering the object you're provided, but there's actually a bigger one with this method: if the function is called with no options or `null` or `undefined` it will blow up with a rather unhelpful message.

Unless you have a truly huge set of options, I'd suggest using

    var final_opts = _.defaults({}, opts, defaults);
instead: `opts` being `null` or `undefined` will be equivalent to an empty object.
Re:Default Parameters in JavaScript by STRML on Thursday March 21, 2013 @12:36PM (#5416432)
This is a good point, and unfortunately it means that most of the advantage of using _.defaults() goes by the wayside. It just becomes a matter of personal preference. Thanks for the tip.
Re:Default Parameters in JavaScript by masklinn on Thursday March 21, 2013 @04:09PM (#5418521)
> This is a good point, and unfortunately it means that most of the advantage of using _.defaults() goes by the wayside.

How and why? I don't consider mutating the original object to be an advantage of using _.defaults, unless the object is completely under your control and you're essentially calling `_.defaults(this, defaults)`.