The immediate execution function expression description in JavaScript

  • 2020-05-16 06:19:41
  • OfStack

We're used to seeing anonymous functions like this


(function(){
    console.log("test");
})();

The previous 1 was a self-executing anonymous function (self-executing anonymous function)

It turns out that there is another way to call a function expression immediately (IIFE, Immediately-Invoked Function Expression).

Call the function expression immediately

It is more explicit to call a function expression immediately than to self-execute an anonymous function.

Here are some examples of self-executing functions:


function foo() { foo(); }

As well as

var foo = function() { arguments.callee(); };

More importantly, a function like this might be self-executing anonymous

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


Related articles: