Why Immediately-Invoked Function Expression (IIFE) are different from Self-Executing Anonymus Functions?

StackOverflow https://stackoverflow.com/questions/12508359

  •  03-07-2021
  •  | 
  •  

문제

It is clear that in EcmaScript, functions when invoked create a new execution context. All variables and functions defined within a function may only be accessed inside that function scope. But when we use closures variables and functions may be accessed outside that context. IIFE is a function expression that gets invoked immediately. It is simple.

But why are IIFE different from Self-Executing Anonymus Functions, it is not completely clear to me!?

도움이 되었습니까?

해결책

They are the same, it was renamed to IIFE because an IIFE is not necessarily anonymous, and they do not execute themselves.

consider the following:

(function bleh() {
    alert('I am not anonymous, i have a name!');
})(); //<-- invoked like any other function
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top