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:
Michał Gołębiowski
2015-06-01 23:25:38 +02:00
parent 9c8a3ecdc4
commit bb026fc12c
12 changed files with 97 additions and 2 deletions

View File

@@ -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) {