Get the App
SLTechnology News&Howtos  ›  Development  › 

What is the concept of jquery closure

Shulou Source: shulou.com Published: 2022-05-31 19:52:08 09月11日 Update

This article mainly explains "what is the concept of jquery closure". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what is the concept of jquery closure".

In jquery, closure refers to a function that has the right to access variables in the scope of another function, and is a function that can read internal variables of other functions; closures can be understood as functions defined in the function, and can be accessed externally, which can extend the life cycle of variables and protect private variables. Because the external variables of internal variables are inaccessible, they can prevent modification of variables.

The operating environment of this tutorial: windows10 system, jquery3.2.1 version, Dell G3 computer.

What does jquery closure mean?

Closure definition-A function that has access to variables in the scope of another function.

A closure is a function that can read internal variables (local variables) of other functions.

JQuery closure principle

A closure is an expression (usually a function) that has many variables and the environment that binds them, so these variables are part of the expression.

To put it simply, the function defined in the function can be accessed externally

Advantages of closure

It can reduce the objects of global variables and prevent global variables from being large in the past, making it difficult to maintain.

Prevent modifiable variables because internal variables are externally inaccessible and unmodifiable to ensure security

Read the variables inside the function, and the other is to keep the values of those variables in memory all the time.

In jquery, closures are functions that use external variables and can be obtained without passing parameters.

Closures are written in jquery:

(function ($) {$("div p") .click ();}) (jQuery)

The $in this is just a formal parameter, but jquery is a global variable, so it will be executed automatically without calling the function, or in two steps

Is converted into a normal function, first write the function, and then call.

Thank you for your reading, these are the contents of "what is the concept of jquery closure". After the study of this article, I believe you have a deeper understanding of what the concept of jquery closure is, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Variables functions closures that is concepts global learning functions content environment expressions security advantages memory writing principles just periods objects local. Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux Apple MariaDB vpn Huawei