Skip to main content

Bug Tracker

Side navigation

#14659 closed feature (fixed)

Opened December 31, 2013 09:25PM UTC

Closed March 09, 2014 10:32PM UTC

Avoid use of Object.keys() in cleanData()

Reported by: hiroshi Owned by: m_gol
Priority: low Milestone: 2.1.1
Component: manipulation Version: 2.1.0-beta2
Keywords: Cc:
Blocked by: Blocking:
Description

Object.keys() is still not supported by some old browsers.

http://kangax.github.io/es5-compat-table/

Also ''for in'' is used to iterate event types in other places (i.e. jQuery.event.remove).

for ( type in events ) {
	jQuery.event.remove( elem, type + types[ t ], handler, selector, true );
}

I think we should avoid use of Object.keys() in terms of followings.

  • Browser compatibility
  • Code consistency
Attachments (0)
Change History (9)

Changed December 31, 2013 10:21PM UTC by rwaldron comment:1

Object.keys() is still not supported by some old browsers.

This is not a relevant "issue" for jQuery 2.x, which only supports browsers that _will_ have Object.keys

Changed December 31, 2013 10:25PM UTC by dmethvin comment:2

_comment0: I think the consistency issue is a better argument, since we don't use `Object.keys` anywhere else. However, the good thing about it would be that potentially we could survive augmentation of `Object` if we used this everywhere, since it only enumerates own properties? The for/in makes the code a bit shorter and simpler, I haven't looked to see the impact on gzip though.1388528759194254

I think the consistency issue is a better argument, since we don't use Object.keys anywhere else. However, the good thing about it would be that potentially we could survive augmentation of Object.prototype if we used this everywhere, since it only enumerates own properties? The for/in makes the code a bit shorter and simpler, I haven't looked to see the impact on gzip though.

Changed December 31, 2013 10:33PM UTC by timmywil comment:3

_comment0: While this is not high priority, I think I would prefer to use the for-in loop to save a few bytes. Supporting `Object.prototype` augmentation is not something we've pursued historically and I don't think we would want to make the necessary changes to the 1.x branch to keep it consistent with 2.x if we wanted to start.1388529301933810
component: unfiledevent
priority: undecidedlow
status: newopen
type: bugfeature

While this is not high priority, I think I would prefer to use the for-in loop to save a few bytes. That is, if the argument is for consistency, the bytes would add up if we used Object.keys ubiquitously. Supporting Object.prototype augmentation is not something we've pursued historically and I don't think we would want to make the necessary changes to the 1.x branch to keep it consistent with 2.x if we wanted to start.

Changed January 01, 2014 05:37AM UTC by hiroshi comment:4

I added some analysis. Performance and file size seem better.

https://github.com/jquery/jquery/pull/1472

Changed March 04, 2014 02:31PM UTC by dmethvin comment:5

milestone: None1.11.1/2.1.1

Changed March 05, 2014 01:26AM UTC by dmethvin comment:6

milestone: 1.11.1/2.1.12.1.1

Changed March 09, 2014 10:28PM UTC by m_gol comment:7

owner: → m_gol
status: openassigned

Changed March 09, 2014 10:31PM UTC by m_gol comment:8

component: eventmanipulation

Changed March 09, 2014 10:32PM UTC by Michał Gołębiowski comment:9

resolution: → fixed
status: assignedclosed

Manipulation: don't use Object.keys for consistency

Fixes #14659

Changeset: a96d5bed58f2b30f97d6dd2f5691cd890f62b75f