Skip to content
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

error on for...of statement #176

Open
n-a-m-e opened this issue Feb 1, 2016 · 4 comments
Open

error on for...of statement #176

n-a-m-e opened this issue Feb 1, 2016 · 4 comments

Comments

@n-a-m-e
Copy link

n-a-m-e commented Feb 1, 2016

Firstly thanks for writing jslint, secondly I found this new for-of loop that javascript has
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...of
but js lint throws the error

Expected ';' and instead saw 'of'.
(function(){
    'use strict';
    let arr = [3, 5, 7];
    let i;
    arr.foo = "hello";

    for (i of arr) {
        console.log(i); // logs "3", "5", "7", "hello"
    }
}());

I could always use forEach instead but then I can't break out of the loop

(function () {
    'use strict';
    let arr = [3, 5, 7];
    arr.foo = "hello";
    arr.forEach(function (element, index) {
        console.log(element); // logs "3", "5", "7"
        console.log(index);   // logs "0", "1", "2"
    });
}());

what is your opinion, is the for of loop useful or should I use something else instead.
Thanks

@douglascrockford
Copy link
Collaborator

The for of statement is a new ES6 feature that has not yet been proven to be a good part.

Try arr.every.

Recursion is becoming a better approach than looping.

@Akuli
Copy link

Akuli commented Oct 6, 2024

Could this perhaps be reconsidered? It's been 8 more years, and at least to me, for...of loops did turn out to be a good part. If maintainers agree, I might implement this during the next few weeks.

I'm new to JSLint, and really I like it: it is a self-contained, dependency-free tool that just works without npm hell. The one thing I don't like is that jslint cannot parse my loops.

@douglascrockford
Copy link
Collaborator

I think that is a good idea. We could also relax the restrictions on 'let' in scopes. Some of the JSLint rules were to get us thru some standard transitions, and I think those are way behind us now.

@kaizhu256
Copy link
Member

    function stmt_for() {
        let first;
        let the_for = token_now;
        if (!option_dict.for) {

// test_cause:
// ["for", "stmt_for", "unexpected_a", "for", 1]

            warn("unexpected_a", the_for);
        }
        check_not_top_level(the_for);
        functionage.loop += 1;
        advance("(");
        token_now.free = true;
        if (token_nxt.id === ";") {
...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants
@douglascrockford @kaizhu256 @n-a-m-e @Akuli and others