Learn about JS! /+/-/~ function() {/*...*/}() What does it mean?
Jun 29, 2020 pm 05:41 PMSelf-executing anonymous function:
- Common format: (function() { /* code */ })();
- Explanation: The first pair of brackets surrounding the function (function(){}) returns an unnamed function to the script, and then a pair of empty brackets immediately executes the returned unnamed function. Inside the brackets are the parameters of the anonymous function.
- Function: You can use it to create a namespace. As long as you write all your code in this special function package, it will not be accessible from the outside unless you allow it (add window before the variable, so that the function or the variable becomes global). The code of each JavaScript library is basically organized in this form.
To summarize, the main functions of the execution function are anonymous and automatic execution. The code is already running when it is interpreted.
Other writing methods
(function () { /* code */ } ()); !function () { /* code */ } (); ~function () { /* code */ } (); -function () { /* code */ } (); +function () { /* code */ } ();
Related learning tutorials: javascript tutorial
The above is the detailed content of Learn about JS! /+/-/~ function() {/*...*/}() What does it mean?. For more information, please follow other related articles on the PHP Chinese website!

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

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

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

How to use JS and Baidu Maps to implement map pan function

Recommended: Excellent JS open source face detection and recognition project

Essential tools for stock analysis: Learn the steps to draw candle charts with PHP and JS

PHP and JS Development Tips: Master the Method of Drawing Stock Candle Charts

How to create a stock candlestick chart using PHP and JS

How to use JS and Baidu Maps to implement map polygon drawing function

How to use JS and Baidu Map to implement map click event processing function

How to use JS and Baidu Maps to implement map heat map function
