JQuery + extension Object.prototype = "c.replace is not a function"

I am using jQuery 1.5 in my open source project, and the following line is also present in my own JavaScript code:

/**
 * Object.isEmpty()
 *
 * @returns {Boolean}
 */
Object.prototype.isEmpty = function ()
{
    /**
     * @deprecated Since Javascript 1.8.5
     * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Object
     */
    if ( this.__count__ !== undefined )
    {
        return this.__count__ === 0 ? true : false;
    }

    /* Less-aesthetic method, if above method fails */
    for ( var property in this )
    {
        if ( this.hasOwnProperty(property) )
        {
            return false;
        }
    }
    return true;
};

which simply extends Object.prototype by adding the isEmpty () method [which checks if the object is empty or not). Due to this addition, I get the error "c.replace is not function" in my Firebug console; and my research on the Internet led me to jQuery an error message where I “found out” that the Object.prototype extension not only breaks jQuery, but it is also a bad coding practice. My question is why?

+5
3

ECMA-262 5th Edition ( JavaScript 1.8.5) Object.defineProperty Object.defineProperties, enumerable false. Chrome 5, Safari 5, Firefox 4 Internet Explorer 9 , V8 (, Node.js).

+5

, Object.prototype for ... in.

Javascript, :

var obj = { "foo": 0, "bar": 42 };

:

for (var key in obj) {
    // Do Something.
}

Object.prototype , , , foo bar, .

, .

+4

1) () ( ) Object?

, .

2) , hasOwnProperty(), ?

, , . , . Object.prototype - .

MyLib.isEmpty(obj) isEmpty(obj) , .

+2
source

All Articles