there is something about finding a use case for a recursive IIFE that just fills me with joy

@vaporeon_ Immediately-Invoked Function Execution! (some people pronounce it as "iffy", I just say "eye eye eff ee")

It's a function that you declare and execute simultaneously :D

@wallhackio Is that a C++ thing or is that also possible in C? Can give me an example, maybe? (I still don't really get it, but that's probably because words are hard and I'm eepy, and I'll get it once I see an example...) :blobcatreach:

Follow

@vaporeon_ it's a functional programming thing and it only seems to be common in JavaScript

Here is an example:

const fib_20 = (function fibonacci(n) {
if (n === 0) return 1;
if (n === 1) return 1;
return fibonacci(n - 1) + fibonacci(n - 2);
})(20);

@vaporeon_ A more practical example I ran into occurred when I implemented an HTTP/HTTPS request library. Internally I used a recursive IIFE to automatically redirect response with 3xx status codes

Sign in to participate in the conversation
📟🐱 GlitchCat

A small, community‐oriented Mastodon‐compatible Fediverse (GlitchSoc) instance managed as a joint venture between the cat and KIBI families.