Bug Tracker


Ticket #6132 (closed enhancement: wontfix)

Opened 4 years ago

Last modified 3 years ago

jQuery.each includes prototype functions

Reported by: agoebel Owned by:
Priority: undecided Milestone: 1.4.2
Component: core Version: 1.4.1
Keywords: each, object, prototype Cc: agoebel@…
Blocking: Blocked by:


I'm not entirely sure if this is deliberate or not, but the way jQuery handles the each method includes anything defined in the prototype.


Object.prototype.newMethod = function() {};
var keys = [],
    map = {
        'a': 1,
        'b': 2,
        'c': 3

jQuery.each( map, function(k,v) {

the keys array has a value of:


The change is pretty trivial. Simply add a hasOwnProperty filter to the object portion of the each method.

//starting from line 556
if ( isObj ) {
    for ( name in object ) {
        if ( !object.hasOwnProperty(name) ) {
        if ( callback.apply( object[ name ], args ) === false ) {

Using this code, keys is:


Which I personally think is what it should be. As an alternative, maybe a flag can be introduced to determine whether or not prototype values are filtered out.

The modified jquery-1.4.2 file is attached. I tested the example and patched code in firefox 3.6, chrome 4.0, and IE8.


jquery-1.4.2.modified.js Download (160.1 KB) - added by agoebel 4 years ago.
jQuery 1.4.2 with $.each modified to exclude prototype/inherited values of an object

Change History

Changed 4 years ago by agoebel

jQuery 1.4.2 with $.each modified to exclude prototype/inherited values of an object

comment:1 Changed 3 years ago by snover

  • Priority set to undecided
  • Status changed from new to closed
  • Resolution set to wontfix

A user can use hasOwnProperty to filter out anything from the prototype that they want to already; this patch only limits the ability for users to decide whether or not they want to access prototype members too.

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


Add a comment

Modify Ticket

as closed

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

Note: See TracTickets for help on using tickets.