Skip to main content

Bug Tracker

Side navigation

#2721 closed bug (wontfix)

Opened April 19, 2008 11:02AM UTC

Closed July 11, 2011 05:19PM UTC

Last modified August 10, 2014 01:10AM UTC

Object.prototype

Reported by: dryabkov Owned by: john
Priority: low Milestone: 1.next
Component: core Version: 1.4.4
Keywords: hasOwnProperty, object.prototype Cc:
Blocked by: Blocking:
Description
<html>
<head>
<script type="text/javascript">
    Object.prototype.test1 = function() {alert('sss')};
</script>
<script src="js/jquery-1.2.3.js" ></script>
</head>
<body>
</body>
</html>

In Firefox2 and Konqueror test1 considered as event handler and called on page refresh (handling event "unload").

Attachments (0)
Change History (20)

Changed April 19, 2008 02:22PM UTC by scott.gonzal comment:1

resolution: → invalid
status: newclosed

Modifying Object.prototype is an extremely bad practice. jQuery is not supported on any page where this occurs.

Changed February 10, 2009 10:33PM UTC by john comment:2

component: eventcore
milestone: 1.2.41.3.2
resolution: invalid
status: closedreopened
version: 1.2.31.3.1

I'm going to re-open this so that we can try and tackle it in a future release.

Changed February 10, 2009 10:33PM UTC by john comment:3

owner: → john
status: reopenednew

Changed July 15, 2009 08:51AM UTC by yehuda comment:5

milestone: 1.3.21.3.3

Changed July 24, 2009 02:50PM UTC by Cheatah comment:6

Fix should be easy:

for (var i in O) {
    if (!O.hasOwnProperty(i)) { continue; }
    // other code stays unchanged
}

The only two problems are:

1.) IE 5.0 and older don't support {}.hasOwnProperty() - but this can be implemented using Object.prototype ...

2.) Find all the for-in-loops ;)

Changed October 25, 2010 11:26PM UTC by rwaldron comment:7

milestone: 1.4
priority: majorlow

Changed October 26, 2010 06:48AM UTC by SlexAxton comment:8

keywords: → hasOwnProperty, object.prototype
milestone: → 1.5
status: newassigned

I don't think this was meant to be changed to 'new' - switching back to open.

Changed October 26, 2010 03:53PM UTC by rwaldron comment:9

Changed January 14, 2011 11:45PM UTC by jitter comment:10

milestone: 1.51.next
version: 1.3.11.4.4

Changed January 14, 2011 11:52PM UTC by jitter comment:11

#7977 is a duplicate of this ticket.

Changed January 14, 2011 11:53PM UTC by jitter comment:12

Yet another test case (extracted from 7977)

Changed April 21, 2011 02:11AM UTC by tianon comment:13

Replying to [comment:6 Cheatah]:

Fix should be easy:
> for (var i in O) {
>     if (!O.hasOwnProperty(i)) { continue; }
>     // other code stays unchanged
> }
> 
The only two problems are: 1.) IE 5.0 and older don't support {}.hasOwnProperty() - but this can be implemented using Object.prototype ... 2.) Find all the for-in-loops ;)

For 1.), it's as simple as adding a jQuery-local function for hasOwnProperty (or even $.hasOwnProperty), similar to this:

function hasOwnProperty(object, prop) {
    if (Object.prototype.hasOwnProperty) {
        return Object.prototype.hasOwnProperty.call(object, prop);
    }
    
    return true; // or a suitable implementation, if one can be implemented easily -- I had seen a good one once, but can't find it now that I need it
}

Then, use this function in $.each, and convert all other for-in loops to use $.each instead (or use this function in each of those, if that's preferable). Win-win?

Changed July 11, 2011 05:19PM UTC by john comment:14

resolution: → wontfix
status: assignedclosed

This isn't something that we're going to fix:

http://docs.jquery.com/Won%27t_Fix

Changed December 18, 2011 03:22PM UTC by dmethvin comment:15

#11053 is a duplicate of this ticket.

Changed April 20, 2012 03:14AM UTC by dmethvin comment:16

#11605 is a duplicate of this ticket.

Changed July 16, 2012 09:11PM UTC by rwaldron comment:17

#12090 is a duplicate of this ticket.

Changed March 27, 2013 01:33AM UTC by rwaldron comment:18

#13671 is a duplicate of this ticket.

Changed April 04, 2013 05:58PM UTC by m_gol comment:19

#13731 is a duplicate of this ticket.

Changed August 10, 2014 01:10AM UTC by rwaldron comment:20

#15208 is a duplicate of this ticket.