Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#9025, #9750 - jQuery.map - bounding values and Functions as no arrays. #368

Closed
wants to merge 8 commits into from

Conversation

rkatic
Copy link
Contributor

@rkatic rkatic commented May 2, 2011

Ensure all values are considered in .map
Bug #9025 to reopen->close (false duplicate).

Ensure that functions with length == 0 (with no arguments) are not traversed as arrays.

ALSO: Ensure that .isArray() is not unnecessarily called when length == 0.

@@ -720,7 +720,9 @@ jQuery.extend({
i = 0,
length = elems.length,
// jquery objects are treated as arrays
isArray = elems instanceof jQuery || length !== undefined && typeof length === "number" && ( ( length > 0 && elems[ 0 ] && elems[ length -1 ] ) || length === 0 || jQuery.isArray( elems ) ) ;
isArray = elems instanceof jQuery || length !== undefined && typeof length === "number" && (
length > 0 && ( ( 0 in elems ) && ( length - 1 in elems ) || jQuery.isArray( elems ) ) ||
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the benefit to doing ( 0 in elems ) over elems [ 0 ]
I was originally thinking performance.. but i guess it varies.. http://jsperf.com/in-vs-arr-key

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Take for example an arguments object which first (or last) value is 0. Currently such object will be traversed as an object, and not as an array! Using the in operator instead, only the presence of the first and last property is checked, and not their values too.

EDIT: Also, seams that using in is generally considerably faster, with the exception of Chrome...

Note that arguments object is not an ideal example here, because their properties as length and callee are generally not enumerable, so it is less important in which way it is traversed. However, other array-like objects can not be ignored (see test of #9025).

EDIT: Seams arguments is still a good example because of #9750.

@rkatic rkatic closed this Jul 12, 2011
@lock lock bot locked as resolved and limited conversation to collaborators Jan 21, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants