Side navigation
#11605 closed bug (duplicate)
Opened April 19, 2012 04:51AM UTC
Closed April 20, 2012 03:14AM UTC
Last modified April 20, 2012 03:14AM UTC
CSS selector slurps up added Object.prototype methods
Reported by: | mathstuf@gmail.com | Owned by: | |
---|---|---|---|
Priority: | undecided | Milestone: | None |
Component: | unfiled | Version: | 1.7.2 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
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:
$(element).position();
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) &&
I think it's pretty well established by now that extending
Object.prototype
is a very bad idea. jQuery does not support it.http://docs.jquery.com/Won%27t_Fix#Object.prototype_Issues
http://stackoverflow.com/questions/6877005/extending-object-prototype-javascript