JavaScript: filter() for Objects
<p>ECMAScript 5 has the <code>filter()</code> prototype for <code>Array</code> types, but not <code>Object</code> types, if I understand correctly.</p>

<p>How would I implement a <code>filter()</code> for <code>Object</code>s in JavaScript? </p>

<p>Let's say I have this object:</p>

<pre><code>var foo = {
    bar: "Yes"
};
</code></pre>

<p>And I want to write a <code>filter()</code> that works on <code>Object</code>s:</p>

<pre><code>Object.prototype.filter = function(predicate) {
    var result = {};

    for (key in this) {
        if (this.hasOwnProperty(key) &amp;&amp; !predicate(this[key])) {
            result[key] = this[key];
        }
    }

    return result;
};
</code></pre>

<p>This works when I use it in jsfiddle (<a href="http://jsfiddle.net/MPUnL/4/" rel="nofollow">http://jsfiddle.net/MPUnL/4/</a>), but when I add it to my site that uses jQuery 1.5 and jQuery UI 1.8.9, I get JavaScript errors in FireBug.</p>
