Immediate function using JavaScript ES6 arrow functions

后端 未结 2 1291
花落未央
花落未央 2020-11-30 00:58

Does anyone know how to write an immediate function using ES6 arrow syntax?

Here\'s the ES3/5 way of doing it:

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


        
2条回答
  •  心在旅途
    2020-11-30 01:52

    From the Arrow functions examples,

    (() => "foobar")() // returns "foobar" 
    

    So, the function invocation operator should be outside.

    (() => {
      //...
    })();
    

    Sample: http://www.es6fiddle.net/hsb8s1sj/

提交回复
热议问题