JavaScript Closure examples | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

JavaScript Closure examples

I'm interested to see if anyone has really good examples of using JS Closures.

16th Mar 2018, 8:27 AM
Mike Choy
Mike Choy - avatar
3 Answers
+ 7
Hi Mike... Sorry for missing your question on this. If you are still interested in seeing an example, I made one about 6 months ago in response to the question below: https://www.sololearn.com/Discuss/669904/?ref=app https://code.sololearn.com/W41q8fBJ4tO4/?ref=app
24th Mar 2018, 1:25 PM
David Carroll
David Carroll - avatar
+ 3
So just replying to my own question having now done some more learning. The obvious place is to replace global variables. A really common use case is in managing animation frame counters. Here is example in my Divers watch app, which has to keep count of the rotation of the bezel using the mouse scroll wheel https://code.sololearn.com/W83YJn5p0VmT/#js
24th Mar 2018, 12:25 PM
Mike Choy
Mike Choy - avatar
+ 1
Hi David some great examples cheers
24th Mar 2018, 2:24 PM
Mike Choy
Mike Choy - avatar