mirror of
https://github.com/jquery/jquery.git
synced 2026-02-02 01:25:10 -05:00
Core: Make jQuery objects iterable
Make iterating over jQuery objects possible using ES 2015 for-of:
for ( node of $( "<div id=narwhal>" ) ) {
console.log( node.id ); // "narwhal"
}
Fixes gh-1693
This commit is contained in:
10
src/core.js
10
src/core.js
@@ -425,6 +425,16 @@ jQuery.extend({
|
||||
support: support
|
||||
});
|
||||
|
||||
// JSHint would error on this code due to the Symbol not being defined in ES5.
|
||||
// Defining this global in .jshintrc would create a danger of using the global
|
||||
// unguarded in another place, it seems safer to just disable JSHint for these
|
||||
// three lines.
|
||||
/* jshint ignore: start */
|
||||
if ( typeof Symbol === "function" ) {
|
||||
jQuery.fn[ Symbol.iterator ] = arr[ Symbol.iterator ];
|
||||
}
|
||||
/* jshint ignore: end */
|
||||
|
||||
// Populate the class2type map
|
||||
jQuery.each("Boolean Number String Function Array Date RegExp Object Error".split(" "),
|
||||
function(i, name) {
|
||||
|
||||
Reference in New Issue
Block a user