Home  >  Article  >  Web Front-end  >  Introduction to immediate execution function expressions in JavaScript_javascript skills

Introduction to immediate execution function expressions in JavaScript_javascript skills

WBOY
WBOYOriginal
2016-05-16 16:09:111601browse

We are used to seeing this anonymous function

Copy code The code is as follows:

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

What I have been calling before is self-executing anonymous function

I found out that there is another name: Immediately-Invoked Function Expression (IIFE, Immediately-Invoked Function Expression)

Call function expression immediately

Compared with self-executing anonymous functions, the meaning of immediately calling function expressions is clearer.

Self-executing functions include the following examples:

Copy code The code is as follows:

function foo() { foo(); }

and
Copy code The code is as follows:

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

More importantly, something like the following might be a self-executing anonymous function
Copy code The code is as follows:

var foo = function() { foo(); };
Statement:
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