From the course: JavaScript: Closures

Unlock this course with a free trial

Join today to access over 25,500 courses taught by industry experts.

Create parallel closures

Create parallel closures - JavaScript Tutorial

From the course: JavaScript: Closures

Create parallel closures

- [Tutor] Even though the ability to return a closure can be helpful in code organization, this feature of JavaScript wouldn't necessarily be very powerful if a function could return only a single reference. If I wanted to reuse the same function elsewhere in my application, but had all of my uses referencing the same closed over values, my code would quickly become redundant and harder to maintain. Fortunately, this is not how closures work. In fact, one of the super powers of a function that creates a closure is that it can create references to multiple closed over variables that are independent of each other. Let's explore this in our code. We have a function that creates a closure to log clicks on the buttons at the top of the app. But how about if we want to reuse this function to also log each time a user moved the mouse over one of the items in the product gallery further down the page? So in the browser,…

Contents