In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces javascript how to form closure related knowledge, detailed and easy to understand, simple and fast operation, has a certain reference value, I believe that everyone will have a harvest after reading this javascript how to form closure article, let's take a look at it.
In JavaScript, a closure is formed when an inner function is called outside the outer function that contains the inner function; a closure is a stack area that does not release resources when the function returns, and a closure is a reference to a function variable that is active when the function returns.
Operating environment of this tutorial: Windows 10 system, Javascript version 1.8.5, Dell G3 computer.
When does javascript form closures?
The official interpretation of closure is that it is an expression (usually a function) that has many variables and the environment to which they are bound, so that the variables are part of the expression.
Features of closures:
1. As a reference to a function variable, it is active when the function returns.
2. A closure is an area of the stack that does not release resources when a function returns.
Simply put, javascript allows the use of internal functions--that is, function definitions and function expressions are located within the function body of another function. Moreover, these inner functions have access to all local variables, parameters, and other inner functions declared in the outer function in which they are located.
Closures are formed when one of these inner functions is called outside the outer function that contains them.
function closure(){var str = "I'm a part variable. ";return function(){alert(str);}}var fObj = closure();fObj();
In the above code, str is a local variable defined in the closure function. If str cannot be accessed after the closure function is called, str will be released after the function is executed.
However, since the function closure returns an internal function, and the returned function references str variables, str may be referenced after the closure function is executed, so the resources occupied by str will not be recycled. This closure forms a closure.
About "javascript how to form closure" the content of this article is introduced here, thank you for reading! I believe everyone has a certain understanding of "how javascript forms closures" knowledge. If you still want to learn more knowledge, please pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.