Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to eliminate closures by javascript

Shulou Source: shulou.com Published: 2022-05-31 11:51:47 09月23日 Update

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.

Tags: Closures articles content functions spaces propriety keys memory variables just places instances external ideas members new knowledge time more mechanisms steps Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Linux Huawei Docker Xiaomi