Bug Tracker

Modify

Ticket #2721 (closed bug: wontfix)

Opened 6 years ago

Last modified 13 months ago

Object.prototype

Reported by: dryabkov Owned by: john
Priority: low Milestone: 1.next
Component: core Version: 1.4.4
Keywords: hasOwnProperty, object.prototype Cc:
Blocking: Blocked by:

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

comment:1 Changed 6 years ago by scott.gonzal

  • Status changed from new to closed
  • Resolution set to invalid

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

comment:2 Changed 5 years ago by john

  • Status changed from closed to reopened
  • Resolution invalid deleted
  • Version changed from 1.2.3 to 1.3.1
  • Component changed from event to core
  • Milestone changed from 1.2.4 to 1.3.2

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

comment:3 Changed 5 years ago by john

  • Owner set to john
  • Status changed from reopened to new

comment:5 Changed 5 years ago by yehuda

  • Milestone changed from 1.3.2 to 1.3.3

comment:6 follow-up: ↓ 13 Changed 5 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 3 years ago by rwaldron

  • Priority changed from major to low
  • Milestone 1.4 deleted

comment:8 Changed 3 years ago by SlexAxton

  • Keywords hasOwnProperty, object.prototype added
  • Status changed from new to assigned
  • Milestone set to 1.5

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

comment:9 Changed 3 years ago by rwaldron

comment:10 Changed 3 years ago by jitter

  • Version changed from 1.3.1 to 1.4.4
  • Milestone changed from 1.5 to 1.next

comment:11 Changed 3 years ago by jitter

#7977 is a duplicate of this ticket.

comment:12 Changed 3 years ago by jitter

Yet another  test case (extracted from 7977)

comment:13 in reply to: ↑ 6 Changed 3 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 3 years ago by john

  • Status changed from assigned to closed
  • Resolution set to wontfix

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

comment:15 Changed 2 years ago by dmethvin

#11053 is a duplicate of this ticket.

comment:16 Changed 2 years ago by dmethvin

#11605 is a duplicate of this ticket.

comment:17 Changed 21 months ago by rwaldron

#12090 is a duplicate of this ticket.

comment:18 Changed 13 months ago by rwaldron

#13671 is a duplicate of this ticket.

comment:19 Changed 13 months ago by m_gol

#13731 is a duplicate of this ticket.

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.