Home > Common Problem > body text

What is closure

藏色散人
Release: 2019-08-03 09:49:25
Original
9184 people have browsed it

What is closure

What is a closure?

In computer science, closure (English: Closure), also known as lexical closure (Lexical Closure) or function closure (function closures), is a function that references free variables. The referenced free variable will remain with the function even after it has left the environment in which it was created.

So, there is another way of saying that a closure is an entity composed of a function and its associated reference environment. Closures can have multiple instances at runtime, and different reference environments and the same function combination can produce different instances.

The concept of closure appeared in the 1960s, and the earliest programming language to implement closure was Scheme. Since then, closures have been widely used in functional programming languages ​​such as ML and LISP. Many imperative programming languages ​​have also begun to support closures.

In some languages, when another function can be (nested) defined in a function, if the inner function refers to the variables of the outer function, a closure may occur. At runtime, once the outer function is executed, a closure is formed that contains the code of the inner function and references to the variables in the required outer function. The variable referenced is called the upvalue.

The term closure is often confused with anonymous functions. This may be because the two are often used together, but they are different concepts.

The above is the detailed content of What is closure. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template