remove default values from an object
<p>I have two javascript objects:</p>

<pre><code>var a = {
    x: 1, 
    y: {
        faz: 'hello', 
        baz: ''
    },
    z: [1, 2]
};


var defaults = {
    x: 2,
    y: {
        faz: '', 
        baz: ''
    },
    z: [1, 2]
};
</code></pre>

<p>I want to only keep the fields of <code>a</code> that are <strong>different</strong> from the default:</p>

<pre><code>a = remove_defaults(a, defaults); // &lt;---- i need this fnc
{
    x: 1,
    y: {
        faz: 'hello'
    }
}
</code></pre>

<p>The goal is to remove default values from an object that serves as a state (via URL). The state can have nested fields, so a shallow compare is not enough. The leaf values are all primitive (number, string, bool).</p>

<p><em>(this is a bit like the opposite of <code>underscore.js</code>'s <code>_.defaults()</code> method)</em></p>

<p>What is the best way to achieve this?</p>

<hr>

<p>The solution can use <code>underscore.js</code> if that helps, but no <code>jquery</code>.</p>
