Bug Tracker

Opened 10 years ago

Closed 6 years ago

Last modified 3 years ago

#2721 closed bug (wontfix)

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").

Change History (20)

comment:1 Changed 10 years ago by scott.gonzal

Resolution: invalid
Status: newclosed

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

comment:2 Changed 9 years ago by john

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.

comment:3 Changed 9 years ago by john

Owner: set to john
Status: reopenednew

comment:5 Changed 8 years ago by yehuda

Milestone: 1.3.21.3.3

comment:6 Changed 8 years ago by 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 ;)

comment:7 Changed 7 years ago by Rick Waldron

Milestone: 1.4
Priority: majorlow

comment:8 Changed 7 years ago by SlexAxton

Keywords: hasOwnProperty object.prototype added
Milestone: 1.5
Status: newassigned

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

comment:9 Changed 7 years ago by Rick Waldron

comment:10 Changed 7 years ago by jitter

Milestone: 1.51.next
Version: 1.3.11.4.4

comment:11 Changed 7 years ago by jitter

#7977 is a duplicate of this ticket.

comment:12 Changed 7 years ago by jitter

Yet another test case (extracted from 7977)

comment:13 in reply to:  6 Changed 6 years ago by tianon

Replying to 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?

comment:14 Changed 6 years ago by john

Resolution: wontfix
Status: assignedclosed

This isn't something that we're going to fix: http://docs.jquery.com/Won%27t_Fix

comment:15 Changed 6 years ago by dmethvin

#11053 is a duplicate of this ticket.

comment:16 Changed 5 years ago by dmethvin

#11605 is a duplicate of this ticket.

comment:17 Changed 5 years ago by Rick Waldron

#12090 is a duplicate of this ticket.

comment:18 Changed 5 years ago by Rick Waldron

#13671 is a duplicate of this ticket.

comment:19 Changed 5 years ago by m_gol

#13731 is a duplicate of this ticket.

comment:20 Changed 3 years ago by Rick Waldron

#15208 is a duplicate of this ticket.

Note: See TracTickets for help on using tickets.