Can we say that it is IIFE?!? - In Javascript

As you know in Javascript, the following expression is very often used as IIFE ( I immediately I nvoked F unaction E ):

(function(){
  //code ...
})();

I wonder if we can say that the following expression is IIFE (when no return value is required):

new function(){
 //code ...
}

Or

new function(global){
  //code..
}(this);

Even if it is an object. Thank.

Answer:

[Thanks @le_m, @ vol7ron and @Bergi, here is a short answer] Can we say that his next expression is IIFE ( I immediately I nvoked F unction E xpression)?

new function(){
 //code ...
}

or

new function(global){
  //code..
}(this);

. ? , ( ).

+4
2

new function(){ ... } a IIFE?

IIFE I I nvoked F unction E Xpression. FunctionExpression :

BindingIdentifierₒₚₜ (FormalParameters ) {FunctionBody}

, ? :

"type": "ExpressionStatement",
"expression": {
    "type": "NewExpression",
    "callee": {
        "type": "FunctionExpression",
        "params": [],
        "body": {
           ...
    },
    "arguments": []
}

, , NewExpression.

? , - . [[Construct]] . - .

, IIFE, . I mmeditately I nvoked C onstructor IIC ( @vol7ron, @Bergi , ).

+2

, (IIFE), .

MDN:

IIFE ( ) - JavaScript , , .

new function(){
 //code ...
}

, , Javascript .

Wikipedia:

expressio - JavaScript, JavaScript. , , , , .

.

+3

Source: https://habr.com/ru/post/1678464/


All Articles