I'm not up-to-date regarding JS programming, so: why is this solved as it is, i.e. as anonymous function that is immediately called? First idea would be to prevent leaking anything into a global context but this shouldn't be an issue here. Can anyone explain?
var supported = (() => {
try {
if (
typeof WebAssembly === "object" &&
typeof WebAssembly.instantiate === "function"
) {
const module = new WebAssembly.Module(
Uint8Array.of(0x0, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00)
);
if (module instanceof WebAssembly.Module)
return (
new WebAssembly.Instance(module) instanceof WebAssembly.Instance
);
}
} catch (e) { }
return false;
})();
Edit: is it maybe to save one from having to think about leaking anything, i.e. wrap everything in (() => { ... })(); and call it a day?