That is called "Immediately Invoked Function Expression" (IIFE) and as you 
said "canvas" will receive the value returned by that function. You can 
find more information about how it works at 
https://developer.mozilla.org/en-US/docs/Glossary/IIFE.

On Thursday, March 31, 2022 at 4:19:29 AM UTC-3 [email protected] wrote:

> 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/3b4c56f6-cf13-4870-8b12-67566fbaf7c9n%40googlegroups.com.

Reply via email to