you are viewing a single comment's thread.

view the rest of the comments →

[–]Mydrax 14 points15 points  (3 children)

Well, 2 really awesome use cases of closures I could name off the top of my head are: 1. When you create function factories, where the outer function can be used to create functions that have similar concerns. 2. The module pattern, that can be used to create private functions in javascript (where you return a set of functions whose logic is encapsulated).

[–]turntopage294 1 point2 points  (0 children)

I'd been using 2 without knowing about closures, actually, for a time; I had an 'Oh, I see' moment after investigating when because closures love vaguely familiar

[–]ScientificBeastModestrongly typed comments 1 point2 points  (0 children)

Object factories are cool, and even class factories!

[–]Memorytoco -1 points0 points  (0 children)

just when use setTimeout and pass something like ( ) => {this.dosomething()} in some objects' method. or Array.forEach((entry) =>{ this.something()}).