Opened 9 years ago
Closed 9 years ago
#14659 closed feature (fixed)
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
Change History (9)
comment:1 Changed 9 years ago by
comment:2 Changed 9 years ago by
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.
comment:3 Changed 9 years ago by
Component: | unfiled → event |
---|---|
Priority: | undecided → low |
Status: | new → open |
Type: | bug → feature |
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.
comment:4 Changed 9 years ago by
I added some analysis. Performance and file size seem better. https://github.com/jquery/jquery/pull/1472
comment:5 Changed 9 years ago by
Milestone: | None → 1.11.1/2.1.1 |
---|
comment:6 Changed 9 years ago by
Milestone: | 1.11.1/2.1.1 → 2.1.1 |
---|
comment:7 Changed 9 years ago by
Owner: | set to m_gol |
---|---|
Status: | open → assigned |
comment:8 Changed 9 years ago by
Component: | event → manipulation |
---|
comment:9 Changed 9 years ago by
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Manipulation: don't use Object.keys for consistency
Fixes #14659
Changeset: a96d5bed58f2b30f97d6dd2f5691cd890f62b75f
This is not a relevant "issue" for jQuery 2.x, which only supports browsers that _will_ have Object.keys