xgqfrms xgqfrms - 23 days ago 7
Javascript Question

How to using ES6 Arrow function to realize (function es6_test(){})(); using Immediately-Invoked Function Expression (IIFE))?

How to using ES6 Arrow function to realize (function es6_test(){})();

using Immediately-Invoked Function Expression (IIFE)) ?



window.onload = function(t){
var p = document.getElementById('print');
p.onclick = function(){
try {
print();
} catch(t) {
alert("Your browser does not support `print()` method.");
}
};
}();

// ES 6 + IIFE
window.onload = ((t) => {
let p = document.getElementById('print');
p.onclick = () => {
try {
print();
} catch(t) {
alert("Your browser does not support `print()` method.");
}
};
}());
// Douglas Crockford's style




Answer

Surround it with parentheses:

(() => console.log('hello'))()
Comments