(Function () {}) () usage and advantages _ javascript skills
Source: Internet
Author: User
(Function () {}) () usage and advantages in google's ad js, found such a statement
// I used alert ("test") to replace the statements in it.
(Function () {alert ("test ")})()
Tested, similar to directly executing
Alert ("test ")
So what are the advantages of this usage? Let's talk about it!
Function xx (){...}
Equivalent
Var xx;
Xx = function (){...}
Function () {...} returns a Function object.
(Function object) () is to call this Function
The intuitive advantage is that several statements that need to be executed in sequence are organized into a unit, so that the logic is clear and there is no need to name them.
Possible for saving: The anonymous function is like a temporary variable and can be destroyed immediately after execution.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service