Skip to content

Make jQuery collections for-of-able #1693

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

Closed
simevidas opened this issue Oct 10, 2014 · 14 comments · Fixed by #2369
Closed

Make jQuery collections for-of-able #1693

simevidas opened this issue Oct 10, 2014 · 14 comments · Fixed by #2369
Assignees
Labels
Milestone

Comments

@simevidas
Copy link

Chrome 38 added support for ES6 for-of. I'm proposing that jQuery collections are made compatible with this statement, which can be achieved with this line (from discussion on Twitter):

jQuery.prototype[Symbol.iterator] = Array.prototype.values;

Live demo: http://jsbin.com/movuxu/1/edit (view in Chrome)

@dmethvin
Copy link
Member

Isn't it a bit early to be doing this inside jQuery itself? If its just a line, the person using it knows whether their environment is going to be ES6 only. We don't know that.

@simevidas
Copy link
Author

Yes, probably too early :) Just wanted to get general feedback.

@dmethvin
Copy link
Member

Hard to argue with one line of code! 😸 If you're in an environment where you know it's ES6, maybe a Phonegap/Cordova app in a year or two, it could be very handy. I don't think we'll keep this ticket open for that amount of time though?

@simevidas
Copy link
Author

Agree

@simevidas
Copy link
Author

I'm just going to drop this screenshot here. Once ES6 code becomes more common, this syntax comparison will be useful:

woohoo

@sophiebits
Copy link

I'd love to see this. Would make using jQuery with Babel more palatable.

@timmywil
Copy link
Member

You know, I'm not actually against this.

@mgol
Copy link
Member

mgol commented May 19, 2015

It'd be cool to have this natively in 3.0; even if simple. :)

@mgol
Copy link
Member

mgol commented May 19, 2015

The biggest problem is size, I guess. The following:

if ( typeof Symbol !== "undefined" && Symbol.iterator ) {
    jQuery.fn[Symbol.iterator] = [][Symbol.iterator];
}

increases the gzipped size by 32 bytes. Other forms seem larger.

@mgol
Copy link
Member

mgol commented May 19, 2015

Since there is no definite decision yet, let's reopen for now.

@mgol mgol reopened this May 19, 2015
@timmywil timmywil added this to the 3.0.0 milestone Jun 1, 2015
@mgol mgol self-assigned this Jun 1, 2015
@mgol
Copy link
Member

mgol commented Jun 1, 2015

We've decided we're going to do it in 3.0.0. I'm taking it.

mgol added a commit to mgol/jquery that referenced this issue Jun 1, 2015
Make iterating over jQuery objects possible using ES 2015 for-of:

    for ( node of $( "<div id=narwhal>" ) ) {
        console.log( node.id ); // "narwhal"
    }

Fixes jquerygh-1693
@mgol
Copy link
Member

mgol commented Jun 1, 2015

PR: #2369

mgol added a commit to mgol/jquery that referenced this issue Jun 4, 2015
Make iterating over jQuery objects possible using ES 2015 for-of:

    for ( node of $( "<div id=narwhal>" ) ) {
        console.log( node.id ); // "narwhal"
    }

Fixes jquerygh-1693
mgol added a commit to mgol/jquery that referenced this issue Jun 4, 2015
Make iterating over jQuery objects possible using ES 2015 for-of:

    for ( node of $( "<div id=narwhal>" ) ) {
        console.log( node.id ); // "narwhal"
    }

Fixes jquerygh-1693
mgol added a commit to mgol/jquery that referenced this issue Jun 4, 2015
Make iterating over jQuery objects possible using ES 2015 for-of:

    for ( node of $( "<div id=narwhal>" ) ) {
        console.log( node.id ); // "narwhal"
    }

Fixes jquerygh-1693
mgol added a commit to mgol/jquery that referenced this issue Jun 13, 2015
Make iterating over jQuery objects possible using ES 2015 for-of:

    for ( node of $( "<div id=narwhal>" ) ) {
        console.log( node.id ); // "narwhal"
    }

Fixes jquerygh-1693
mgol added a commit that referenced this issue Jun 13, 2015
Make iterating over jQuery objects possible using ES 2015 for-of:

    for ( node of $( "<div id=narwhal>" ) ) {
        console.log( node.id ); // "narwhal"
    }

(partially cherry-picked from bb026fc)

Fixes gh-1693
mgol added a commit that referenced this issue Nov 10, 2015
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
@dmethvin dmethvin modified the milestones: 1.12/2.2, 3.0.0 Jan 7, 2016
@lock lock bot locked as resolved and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

Successfully merging a pull request may close this issue.

7 participants