JavaScript closures...
-
Since I just ran across yet another person who's technically brilliant (in other areas) but doesn't understand what a closure is in JavaScript... And it probably doesn't help that most of the JS articles give lousy explanations (because they don't know it themselves most likely). In plain English, a closure is not just a function inside a function. That's a nested function. A closure _retains_ its lexical state (variables) after the parent function has exited. Now, technically you can create a closures and never leverage this, in which case it'll just look like a function in a function. Which is where I assume why some think that's what a closure is. But, putting a function in a function in another language is not a closure unless there is retention. Exhibit A:
function bro() {
let dude = 'Howdy Partner';return function bruh() {
console.info(dude);
}();
}// prints Howdy Partner
bro().bruh;I'm convinced the only reason JS is considered hard is the sheer amount of FUD out there by peeps who don't study it and use terms from it to sound cool. So, you're welcome. :laugh:
Jeremy Falcon