Ok, I think I get it, 'canvas' will end up bound to the value returned by 
the function call, not the function itself so it is indeed a way to call an 
'init' function once! Is that about right?

On Thursday, March 31, 2022 at 1:34:41 PM UTC+13 Mark Sibly wrote:

> Hi,
>
> I'm a little confused by this code in index.html:
> ```
> canvas: (function() {
>
>         var canvas = document.getElementById('canvas');
>         canvas.addEventListener("webglcontextlost", function(e) { 
> alert('WebGL context lost. You will need to reload the page.'); 
> e.preventDefault(); }, false);
>
>         return canvas;
>     })(),
> ```
> What's the deal with the weird `(function(){...})();` syntax? Other 
> functions in index.html don't seem to do this.
>
> Is it something to do with only running the function code once? Otherwise 
> it seems like a weglcontextlost listener would be added each time canvas() 
> was called!
>
> Bye,
> Mark
>

-- 
You received this message because you are subscribed to the Google Groups 
"emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/emscripten-discuss/bf630600-c0bb-46de-9e6a-175385252374n%40googlegroups.com.

Reply via email to