What is this code doing?

What is this code doing?

Object.filter = function( obj, predicate) {
    var result = {}, key;

    for (key in obj) {
        if (obj.hasOwnProperty(key) && !predicate(obj[key]){ //really confused about the !predicate(obj[key]) part
            result[key] = obj[key];

    return result;


Can you show an example of how you want to use the filter? For example, I assume obj would be an object of some sort, but what would you be assigning to assigning to predicate argument in the call to this filter function? Can you fill in the blanks below?

var obj = {'type': 'dog', 'color': 'grey', 'legs': 4}; // the object
var predicate = ?????;

var filteredObj = obj.filter(obj,predicate);

How are you defining predicate above? It appears to be some kind of function, but what does it look like?