Articles about the concept of "closures" are overwhelming online, basically has been pulpy, but sometimes always feel read so many articles or Yunshan, of course, because of its own more difficult to understand and involved in more knowledge, there is a very important reason is that many tutorials on the internet may have some misunderstanding, Or the focus is different, the following is a simple example of a code to introduce what is a closed package.
Code Instance One:
function A () {
var webname= "cloud-dwelling community";
Console.log (WebName);
}
A ()
The above is a very simple piece of code, and when the function is done, it will be released from memory, inside the declaration of the local variables will be released in memory, nature can not be accessed, in many cases on the Internet, mostly involved in the scope problem, in fact, once involved in the scope of the problem and the "closure" concept on the digress, Although the scope and "closure" have a certain relationship.
Let's look at a piece of code:
function A () {
var webname= "cloud-dwelling community";
Function Show () {
console.log (webName);
}
return show;
var func = a ();
Func ();
The above code forms a typical closure, and after function a () is executed, the variable webname declared inside it can still be used.
Having said so much, what is the closure, the following summary:
A closure is a concept that describes a phenomenon in which memory resides after the function has been released, and it is easy to understand the closure if you grasp the core concept.
The above JavaScript closure concept simple analysis (recommended) is a small series to share all the content, hope to give you a reference, but also hope that we support the cloud-dwelling community.