Skip to content

Use of setTimeout in Closures documentation is confusing #565

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
gene1wood opened this issue Oct 17, 2014 · 4 comments
Closed

Use of setTimeout in Closures documentation is confusing #565

gene1wood opened this issue Oct 17, 2014 · 4 comments
Labels
Chapter: javascript-101 Removed, since https://github.com/jquery/learn.jquery.com/pull/622

Comments

@gene1wood
Copy link

https://github.com/jquery/learn.jquery.com/blob/master/page/javascript-101/closures.md

// Each function executed within the loop will reference
// the last value stored in i (5).
// This won't behave as we want it to - every 100 milliseconds, 5 will alert
for ( var i = 0; i < 5; i++ ) {
    setTimeout(function() {
        alert( i );
    }, i * 100 );
}

In Javascript-101 in the closures chapter, the setTimeout method is used before it's introduced what that is. This example would be easier to understand if it used something different that had already been introduced in previous chapters.

I haven't been able to think of an alternative example that exhibits the behavior that the existing example does (but this likely stems from being in the process of learning js myself).

@arthurvr
Copy link
Member

arthurvr commented Dec 5, 2014

Agreed. Would you consider setTimeout as being part of the javascript 'basics'? If so, I'il PR an explanation. If not, I'il remove the reference to it in a PR.

@gene1wood
Copy link
Author

For myself (as a n00b to javascript) going through the docs from the beginning, I didn't know what setTimeout was and to understand the example needed to go and find a reference outside the jquery docs, figure out what the method was and what it did, then try to re-interpret the docs. I'm still new enough to javascript to not actually know how core/essential/frequently used setTimeout is to know if it should be explained or removed. I'd defer to you or anyone who's a more experienced js developer to know how fundamental setTimeout is.

@arthurvr
Copy link
Member

arthurvr commented Dec 8, 2014

I'd opt to get it out the example right there. Later on, an extra post on Javascript' timing (setTimeout, but also setInterval) inside of Javascript 101 maybe?

@gene1wood
Copy link
Author

@arthurvr Yes, sounds good to me.

@arthurvr arthurvr added the Chapter: javascript-101 Removed, since https://github.com/jquery/learn.jquery.com/pull/622 label Jan 20, 2015
Krinkle pushed a commit that referenced this issue Apr 9, 2024
Fixes gh-257
Fixes gh-20
Fixes gh-58
Fixes gh-70
Fixes gh-375
Fixes gh-565
Fixes gh-615
Closes gh-622
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Chapter: javascript-101 Removed, since https://github.com/jquery/learn.jquery.com/pull/622
Development

No branches or pull requests

2 participants