title: Side-effect free version of Underscore.js default function?
body: <p>To initialize an object using default values I am using Underscore's <a href="http://underscorejs.org/#defaults" rel="nofollow">default</a> function. According to the documentation, it works like this:</p>
  
  <pre><code>var foo = _.defaults(object, *defaults)
  </code></pre>
  
  <p>It is described as:</p>
  
  <blockquote>
    <p>Fill in undefined properties in object with values from the defaults objects, and return the object. As soon as the property is filled, further defaults will have no effect.</p>
  </blockquote>
  
  <p>Although it basically works fine, there is one thing I always stumble upon: The side effect of manipulating the original object.</p>
  
  <p>If I run</p>
  
  <pre><code>var foo = { bar: 'baz' };
  </code></pre>
  
  <p>and then say</p>
  
  <pre><code>var bar = _.defaults(foo, { dummy: 23 });
  </code></pre>
  
  <p>not only, <code>bar</code> has a property called <code>dummy</code>, the original <code>foo</code> object has been changed as well. My current workaround is:</p>
  
  <pre><code>var bar = _.defaults({}, foo, { dummy: 23 });
  </code></pre>
  
  <p>Unfortunately, you can easily forget this. I think it's quite a strange behavior that the <code>defaults</code> function changes an input parameter as well as returning the result as return value. It should be either or.</p>
  
  <p>How do you deal with that situation? Are there better ways to deal with this?</p>