Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

fix(forEach): handle jQuery objects of length 0 #13171

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Angular.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ msie = document.documentMode;

function isNodeList(obj) {
return typeof obj.length == 'number' &&
typeof obj.item == 'function';
(typeof obj.item == 'function' ||
isString(obj.jquery));
Copy link
Contributor

Choose a reason for hiding this comment

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

It is actually easier to identify jQuery and jqLite instances using instanceof jqLite.

}

/**
Expand Down
5 changes: 5 additions & 0 deletions test/AngularSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1142,6 +1142,11 @@ describe('angular', function() {

forEach(jqObject, function(value, key) { log.push(key + ':' + value.innerHTML); });
expect(log).toEqual(['0:s1', '1:s2']);

log = [];
jqObject = jqLite("<pane></pane>");
forEach(jqObject.children(), function(value, key) { log.push(key + ':' + value.innerHTML); });
expect(log).toEqual([]);
});


Expand Down