Home Web Front-end JS Tutorial Commonly used anonymous functions

Commonly used anonymous functions

Sep 23, 2017 am 09:58 AM
function Anonymous Commonly used

Anonymous function

Anonymous function refers to a function without a name. Anonymous means that there is no name. If you write it directly, an error will be reported. There is no way to use it. There is no function defined. .

So, anonymous functions must be used in combination.

Usage 1, assign a value to a variable/object attribute (register event), and call it through the variable.

2, self-executing, self-calling.

3, passed as a parameter, parameter: function

;(function(){
console.log("呵呵");
})();
Copy after login

//Self-calling function, self-executing function: function declaration and function call together. It is customary to add a semicolon before

to prevent global variable pollution

The above is the detailed content of Commonly used anonymous functions. For more information, please follow other related articles on the PHP Chinese website!

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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Tips for dynamically creating new functions in golang functions Tips for dynamically creating new functions in golang functions Apr 25, 2024 pm 02:39 PM

Tips for dynamically creating new functions in golang functions

Considerations for parameter order in C++ function naming Considerations for parameter order in C++ function naming Apr 24, 2024 pm 04:21 PM

Considerations for parameter order in C++ function naming

How to write efficient and maintainable functions in Java? How to write efficient and maintainable functions in Java? Apr 24, 2024 am 11:33 AM

How to write efficient and maintainable functions in Java?

Comparison of the advantages and disadvantages of C++ function default parameters and variable parameters Comparison of the advantages and disadvantages of C++ function default parameters and variable parameters Apr 21, 2024 am 10:21 AM

Comparison of the advantages and disadvantages of C++ function default parameters and variable parameters

Complete collection of excel function formulas Complete collection of excel function formulas May 07, 2024 pm 12:04 PM

Complete collection of excel function formulas

What are the benefits of C++ functions returning reference types? What are the benefits of C++ functions returning reference types? Apr 20, 2024 pm 09:12 PM

What are the benefits of C++ functions returning reference types?

Advanced usage of reference parameters and pointer parameters in C++ functions Advanced usage of reference parameters and pointer parameters in C++ functions Apr 21, 2024 am 09:39 AM

Advanced usage of reference parameters and pointer parameters in C++ functions

C++ Function Exception Advanced: Customized Error Handling C++ Function Exception Advanced: Customized Error Handling May 01, 2024 pm 06:39 PM

C++ Function Exception Advanced: Customized Error Handling

See all articles