Skip to content

Avoid use of Object.keys() [corrected] #1472

Closed
wants to merge 1 commit into from

6 participants

@k-ori
k-ori commented Dec 31, 2013

Avoid use of Object.create() to keep code consistency for iteration of object properties.

@staabm
staabm commented Dec 31, 2013

Did you perf test the change? Usually You also need to open a bugtracker ticket

@timmywil
jQuery Foundation member

An associated ticket on the bug tracker is necessary.

For more information, see the contributing guidelines.

@timmywil
jQuery Foundation member

Also, I think you meant Object.keys.

@markelog
jQuery Foundation member

/cc @rwaldron

@k-ori
k-ori commented Dec 31, 2013

Thanks for comments! I opened a ticket in bugtracker. http://bugs.jquery.com/ticket/14659
I will recreate a patch to modify wrong commit log if change is accepted.

@staabm Thanks for confirmation. No errors are found in Test Suite. Also I verified that event listeners were removed in my simple test case.

@rwaldron
jQuery Foundation member

The change works fine, but I don't like the rationale given in the ticket.

@k-ori considering my response here: http://bugs.jquery.com/ticket/14659#comment:1, can you provide evidence of a performance improvement?

@k-ori
k-ori commented Jan 1, 2014

[Performance]
I created jsperf benchmark. for-in was faster if hasOwnProperty() is not called (Chrome 31.0/Safari 6.0.5 on OS X 10.8.5).
http://jsperf.com/enumerate-properties

[File size]
for-in is smaller than Object.create(). I quote snippet of build script.

master branch

raw gz minify
245170 72599 dist/jquery.js
83790 29329 dist/jquery.min.js

patched branch

raw gz minify
245096 72570 dist/jquery.js
83743 29307 dist/jquery.min.js

Compared to master @ 537e9ce

raw gz minify
-209 -53 dist/jquery.js
-111 -29 dist/jquery.min.js
@dmethvin
jQuery Foundation member
dmethvin commented Feb 7, 2014

It looks like we're just backing out the change from c1b8edf, which is fine with me if it saves bytes.

@dmethvin dmethvin added this to the 1.11.1/2.1.1 milestone Feb 7, 2014
@dmethvin
jQuery Foundation member

@mzgol addressed this with a slightly different patch in a96d5be . Thanks for pointint this out @k-ori !

@dmethvin dmethvin closed this Mar 14, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.