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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

Zend Studio 13.0.1
Powerful PHP integrated development environment

SublimeText3 English version
Recommended: Win version, supports code prompts!

Notepad++7.3.1
Easy-to-use and free code editor
