var aa=function(){}();

 var bb=(function(){})();

I was asked this question today , This paragraph js There is a difference .

To sum up , Both functions mean immediate execution . But the difference is the order of execution ,aa Function first know function , And then recognize the parentheses .

bb Function is to first put the anonymous function , Execution becomes a function , And then in the .bb Functions are often used in js Package development .

Self executing anonymous functions :

  • A common format :(function() { /* code */ })();
  • explain : Bounding function (function(){}) The first pair of parentheses returns unnamed functions to the script , Then an empty pair of parentheses immediately executes the returned unnamed function , In parentheses are the parameters of anonymous functions .
  • effect : You can use it to create a namespace , Just write all your code in this special function wrapper , Then the outside can't access , Unless you allow ( Add... Before the variable window, So the function or variable becomes global ). various JavaScript The code of the library is basically organized in this way .

To sum up , The main function of execution is   anonymous   and   Automatic execution , The code was already running when it was interpreted .

(function () { /* code */ } ());
!function () { /* code */ } ();
~function () { /* code */ } ();
-function () { /* code */ } ();
+function () { /* code */ } ();

turn :http://www.cnblogs.com/TomXu/archive/2011/12/31/2289423.html

js in ()() More articles on the question

  1. 5.0 JS Introduction to reference types in

    Actually , In front of "js Six types of data " A little bit about reference types . We said earlier js There are six types of data in ( Five basic data types + A reference type ). In the following sections , We'll talk about reference types in detail . 1. ...

  2. 【repost】JS Exception handling method sharing in

    We're writing js In the process , It's hard to avoid some code errors , Need to find out , Sometimes I'm afraid because js Problems lead to poor user experience , Here are some solutions js Fault tolerant statements , Namely js There is no indication of error ( Prevent a yellow triangle in the lower right corner of the browser , want ...

  3. JS Add variables to regular expressions in

    Not long ago, my colleague asked me js How to add variables to regularization , So I wrote a blog to record .   One . Literal In fact, when we define a string , An array , When an object is waiting , We are used to defining it literally , for example : var s = &quo ...

  4. js Detailed explanation of several practical cross domain methods in ( turn )

    Today's research js I found a good blog about cross domain problems , Explained in great detail js The principles of several cross domain approaches , Let's share . Original blog address :http://www.cnblogs.com/2050/p/3191744.html The following text opens ...

  5. About js Medium this

    About js Medium this this yes javascript A very special keyword in , It's also a very complicated mechanism , Study this The first step is to understand this Neither the function itself nor the lexical scope of the function ,this It's actually the function being tuned ...

  6. Table valued functions and JS in split() The connection of

    It's troublesome to use cloud platform for development in the company , Do a lot of functions or some harvest , No way to blog , As a result, when I go home, I have to write out what I remember in my brain . split() This function is no stranger to us , However, there are many fields in the current station, and then these parameters are passed after randomly checking ...

  7. JS in call() And apply Method

    1. Method definition call Method :  grammar :call([thisObj[,arg1[, arg2[,   [,.argN]]]]])  Definition : A method that calls an object , Replace the current object with another object .  explain : call ...

  8. stay node.js in , Using a ORM Architecturally Sequelize, operation mysql Add, delete, modify and query the database

    Sequelize It's based on promise Relational database ORM frame , This library is fully implemented JavaScript Developed and can be used in Node.JS Environment , Easy to use , Support more SQL dialect (dialect),. It currently supports M ...

  9. analysis js Medium constructor and prototype

    stay javascript In the course of using ,constructor and prototype These two concepts are quite important , A deep understanding of these two concepts is very important to understand js Some of the core concepts are very important . When we define a function , Function definition time function ...

  10. How to be in Node.js Merge two complex objects in

    Usually , stay Node.js We can pass underscore Of extend perhaps lodash Of merge To merge two objects , But for complex objects like the following , How to deal with it ? For example, I have the following two object: ...

Random recommendation

  1. Kingdom of Obsession---hdu5943( Binary matching )

    Topic link :http://acm.hdu.edu.cn/showproblem.php?pid=5943 The question : Here are two numbers for you n, s And then let you decide if there is (s+1, s+2, s+3, ... , s+n ...

  2. Cannot be in web Start debugging on the server .Microsoft Visual Studio Remote Debugging Monitor (MSVSMON.EXE) It doesn't seem to be running on a remote computer ,VS2012 Debug error

    1. restart ( It's useless ) 2. Turn off firewall ( It's useless ) 3. Turn on file and printer sharing ( It's useless ) 4. No remote debugging permission , Change to local debugging . Or is it IIS This project did not start in . Or not in IIS Create a new project in .

  3. A strange html On url Parameter problem

    Today I stepped on a pit   Such as xxx.com/xxx/xxx?code=+adfdf   I need to get code=+adfdf But what we got backstage was adfdf, Later, I had to code The value of the to urlencode Processed

  4. iOS Code specification document

    File naming conventions : 1. The project uses the class prefix ZY. 2. Classification and nomenclature + Use it all in the back ZYExtension, example :NSDictionary+ZYExtension.h, Common categories are defined internally and document notes are written . If the function ...

  5. Support wmv、mpg、mov、avi Format of the web video playback code

    this 2 Tian has been working on the related projects of the golden net award , The bigger one is the web video playing , You need to think about different formats of video , And then find the appropriate video player . This time I used 2 There are two ways to process these videos : 1. Use ckplayer Web video player ck ...

  6. Guava - Ordering

    guava in Ordering Class is right Compartor Interface implementation , But it's just an abstract class . When calling Ordering.natural() When the method is used , It will return a NaturalOrdering The object of ,Natur ...

  7. oracle Installation tutorial

    First download oracle 12c Installation package ( There are two components ), After downloading, unzip the two compressed files to the same directory https://pan.baidu.com/s/1ydsClsHv04RAwaoGmHrFVQ ht ...

  8. webapi Framework build a series of blogs

    webapi Framework build a series of blogs webapi Frame building - Create project ( One ) webapi Frame building - Create project ( Two )- With iis Configuration for the deployment environment webapi Frame building - Create project ( 3、 ... and )-webapi owin web ...

  9. linux Modify the maximum number of open files (ulimit command )

    relieve Linux The maximum number of processes and the maximum number of open files in the system :vi /etc/security/limits.conf# Add the following line * soft noproc 65536 * hard noproc 65 ...

  10. django Source code analysis BigIntegerField ( One )

    To analyze django Source code , To learn more django, It's a good way , Unfortunately, it takes a lot of time . therefore , You can analyze as much as you can . This source code analysis is based on 1.4.16 Based on . use sublime Open the downloaded source code , Use ...