Js匿名异步函数
回答下Stack Overflow的问题吧, 参考: https://developer.mozilla.org/en-US/docs/Glossary/IIFE
two way, we just can short a little :)
- simple way
!async function () {
console.log("e",'yibu');
}();
or
(async () => {
console.log("e",'yibu');
})();
//maybe this is better then above
;(async function () {
console.log("e",'yibu');
}());
//this is allmost same
;[ async function () {
console.log("e",'yibu');
}()];
- use [then] this is not absolute “anonymous”
var x=async () => 100;
x().then(
e=>console.log({e})
);
匿名函数有这些写法:
!function(){}(); // => true
~function(){}(); // => -1
+function(){}(); // => NaN
-function(){}(); // => NaN
~(function(){})();
void function(){}();
true && function(){ /* code */ }();
15.0, function(){ /* code */ }();
new function(){ /* code */ }
new function(){ /* code */ }() //If no parameters, the last () is not required
//据说这个赢了
;(function(){}());