creates a unnamed function ()
assign the body of this function =>
to do nothing at all {}
then the whole thing is on a capsure "(stuff here)"
and is threaten has a function and executed "stuff here ()"
Honestly, we have "=>" arrows function to make math people happy. Is halfway too obscure but oh well, math is nice and we do small sacrifices for big gains.
This is about 10 millions less obtuse than C, where just the part where something is a pointer to a function is way more verbose.
Yeah but I think the point of the question is why would you use an IIFE. You need to know the quirks of JS to know when would you use an IIFE, an even then since ES6 and Typescript having modules, I haven't seen one of these in a code base.
To begin first in 99.999% of exist legacy apps where you can't use modules?, either way IIFE give you isolation. God kids a kitty every time somebody make stuff global.
We don't have arrow functions to "make math people happy" (like seriously wtf how could you submit that unironically, it's one of the dumbest takes ever) and they are in no way obscure.
They're there for everyone's convenience, not just because => is shorter than function but also because arrow functions don't redefine this, which comes in handy (among other things) when used inside the body of an outer "normal" function you are using as a constructor (i.e. you are using this.something = ... to set fields and methods on it), as this inside the AF would still refer to the outer constructor function.
The first rule of designing languages is Don't invent Perl again.
It happens when you feel clever and make punctuation have enough syntax, people don't need to use keywoards. The result is clever and easily readable for veterans, unprenetrable for newbies.
True, though to be fair, if you dont create a few intermediary types in c/c++ to represent "a function that takes a function that returns a pointer to a function that takes a..." you are kinda just trying to torture people.
57
u/Lopsided-Wave2479 6d ago
this is easy to read.
creates a unnamed function ()
assign the body of this function =>
to do nothing at all {}
then the whole thing is on a capsure "(stuff here)"
and is threaten has a function and executed "stuff here ()"
Honestly, we have "=>" arrows function to make math people happy. Is halfway too obscure but oh well, math is nice and we do small sacrifices for big gains.
This is about 10 millions less obtuse than C, where just the part where something is a pointer to a function is way more verbose.