-
Notifications
You must be signed in to change notification settings - Fork 487
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
Consider revising example 2.49 #5
Comments
Looking through the other examples in this chapter, none of them use jQuery. I think the best way to handle it would be to write it in vanilla JS and mention how its good to grasp this concept because of how often you end up writing closures when using jQuery... or something. Similar to how jQuery is mentioned at the end of the Testing Type section. I also think that the code examples could be rewritten to something more fundamental, I could be slow but creating closures during loop iterations and Function.bind is a pretty big leep for something labeled "101". :-) |
I agree that it may not make sense to be using jQuery in this chapter for consistency. Would you like to take a stab at integrating the library agnostic version of the code into this section (it's mentioned in the ticket)?. If not, I can do it :) |
Yeah, I can handle that! |
The current article on closures (https://github.com/jquery/learn.jquery.com/blob/master/page/javascript-101/closures.md) no longer contains this jQuery example. I think it's safe to close this given the vintage of this issue. If someone wants to work on the closures article more, there should be a separate issue for that. |
Original ticket:
I'm not sure example 2.49 is a good example to explain what a closure is.
It has a loop, which might be unnecessary, and a click event, which depends upon the user doing something, rather than simply running the program.
By breaking it out into three (3) distinct functions, I was able to step into (F11) it.
I mention F11 vs. F10 because I've grown used to using F10 to step over jQuery itself.
This helped me to realize that closures are simply variables that are kept after the function is completed, the same as 'static' variables are in Visual Basic.
Notes:
Another ticket that mentions this particular example should be revised is: https://github.com/rmurphey/jqfundamentals/issues/56, however they point out that we perhaps shouldn't be using jQuery in the example given it's the JS fundamentals chapter.
Dan appears to have provided a revised version of the example that's library agnostic here https://github.com/rmurphey/jqfundamentals/issues/56, however we should decide whether we want to stick to using jQuery in parts of this chapter or switch to vanilla JavaScript.
Leaving open for discussion.
The text was updated successfully, but these errors were encountered: