JavaScript Closure Concept simple parsing (recommended) _javascript tips

Source: Internet
Author: User
Tags closure

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.