Closure, as the name implies, is to turn steamed buns into steamed buns ~

Steamed bread is full of flour, wrapped with stuffing into a bun

Baozi are steamed buns with stuffing

Closures are functions that have their own runtime environment

Fage is a man who brings his own background music


Some children do not understand the meaning of “own operating environment” ~

Let me give you another example

Everyone has eaten instant noodles. What is the difference between instant noodles and ordinary noodles? Just bring your own flavor bag. The flavor packet is the cooking environment for instant noodles. It simplifies the process of cooking noodles. Let users do not have to practice cooking can also eat delicious inside the cow face.

Closures for functional programming are flavorings for functions. It is convenient for users to call functions. You don’t have to worry about maintaining complex external states. Python, for example, does a lot of things with closures: static private variables, partial functions, monopararguments, decorators…

When you use these features, you are actually eating instant noodles from someone else’s pre-set flavor packet.