How to eliminate closures by javascript
In this article, the editor introduces in detail "how to eliminate closures in javascript". The content is detailed, the steps are clear, and the details are handled properly. I hope this article "how to eliminate closures in javascript" can help you solve your doubts.
Description
1. A key problem in closures is that functions within a function can be called somewhere else.
2. You can reclaim the corresponding memory space simply by dereferencing the fn to the external member variables.
Example
Function add () {var count = 0return function fn () {count++console.log (count)}} var a = add () / / the closure a () / 1a () / / 2a = null / / cancels the connection between an and fn. At this time, the browser recycling mechanism can reclaim the closure space and read here. This article "how to eliminate closures in javascript" has been introduced. If you want to master the knowledge of this article, you still need to practice and use it. If you want to know more about the articles, you are welcome to follow the industry information channel.