Bug Tracker

Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#11605 closed bug (duplicate)

CSS selector slurps up added Object.prototype methods

Reported by: mathstuf@… Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 1.7.2
Keywords: Cc:
Blocked by: Blocking:


I have the following code at the top of my JS code which is from "JavaScript: The Good Parts":

Function.prototype.method = function (name, func) {
    this.prototype[name] = func;
    return this;

Object.method('superior', function (name) {
    var that = this,
        method = that[name];

    return function () {
        return method.apply(that, arguments);

When querying an element's position with:


the "superior" member is treated like a CSS property. The following patch has fixed things for me. I don't know what else might care here though.

--- jquery-1.7.2.js	2012-04-19 00:48:05.032456765 -0400
+++ jquery-1.7.2.string-guard.js	2012-04-19 00:30:24.794445436 -0400
@@ -6722,6 +6722,10 @@
 		var ret, defaultView, computedStyle, width,
 			style = elem.style;
+		if (typeof name !== 'string') {
+			return;
+		}
 		name = name.replace( rupper, "-$1" ).toLowerCase();
 		if ( (defaultView = elem.ownerDocument.defaultView) &&

Change History (2)

comment:1 Changed 11 years ago by dmethvin

Resolution: duplicate
Status: newclosed

I think it's pretty well established by now that extending Object.prototype is a very bad idea. jQuery does not support it.



comment:2 Changed 11 years ago by dmethvin

Duplicate of #2721.

Note: See TracTickets for help on using tickets.