Permalink
Show file tree
Hide file tree
18 comments
on commit
sign in to comment.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Make sure that empty nodelists continue to map properly. Fixes #8993.
- Loading branch information
Showing
2 changed files
with
8 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6c449fd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem of simply adding
length === 0
is that now even functions with no args (length == 0) will be traversed as arrays.I know there is no such unit test (to add?), but $.each has.
6c449fd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rkatic: I'm not sure what you mean. Passing a function to map?
6c449fd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I guess John isn't in favor of isArrayLike either?
6c449fd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@timmywil: Yes. Like in $.each.
@kflorence: Maybe because of number of lines?
6c449fd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not trying to be difficult, but you mean iterate a function? A code example would help me understand.
Also, we tabled isArrayLike for 1.7. I'm not sure John's had time to review the matter.
6c449fd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. For example
$.map( MyClass, handleStatics )
.EDIT: Probably not a big deal. Probably I am just a consistency-freak...
6c449fd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I don't think that's a valid use case either for map or for each. I think iterating an instance(as in the case of a jQuery object) would be workable, but not a raw function.
6c449fd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$.each
does supports iterating functions. Just look in$.each
code and you will seeisObj = length === undefined || jQuery.isFunction( object );
.Also there is a respective unit test for
$.each
.EDIT by @mgol: Fixed code formatting
6c449fd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. I thought you were suggesting there was a regression in map.
6c449fd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I said, probably I am just a consistency-freak...
and for that I am glad that isArrayLike will be considered. :)
6c449fd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fair enough :)
6c449fd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Me too. Glad to hear it will be considered in 1.7!
6c449fd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm kinda glad this is consistent. I know we don't say that jQuery.map supports node lists in the docs, but we had a unit test in core.js that mapped through node lists. This should have either been removed from the unit tests (if we chose not to support node lists) or added support to empty node lists.
6c449fd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jboesch: Rarely you can say that a documentation is also a specification for something. First one is generally a more user-friendly version of the second.
In case of jQuery, documentation is certainly not the specification. Is it needed? Maybe, but it is not simple in case of jQuery... but unit tests are pretty close.
EDIT: Also, i think NodeList are also objects. Why you think it have to be explicitly mentioned to be supported?
6c449fd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rkatic: The docs are the only specification there is at the moment (that I'm aware of). All I'm sayin' is that I think jQuery should either support node lists and go all out (which means handling the empty node lists properly and documenting it), or don't support node lists at all.
6c449fd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I updated my previous comment: Why NodeLists have to be explicitly mentioned if those are also objects?
6c449fd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A node list looks like an object, but technically, it's a node list (with an item method).
You're right about being able to handle them like objects though. Maybe it doesn't need to be documented. shrug
6c449fd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For users, it probably don't have to be mentioned (it's a documentation). For developers there are unit tests (+docs) :)