JavaScript: Getting Closure - Mark Dalgleish
Why Stack Overflow recommends it
Stack Overflow users link it when explaining what IIFEs really are and how closures and function scope work.
Recommended by 1 people across 1 different months, 2012 to 2015.
What it is
A 15-minute conference talk by Mark Dalgleish from Web Directions Code 2012 on how JavaScript's first-class functions and lexical scope enable expressive code. It uses immediately invoked function expressions as a lens to cover function scope, closures, JavaScript "classes", CoffeeScript and ECMAScript 5.
What people said
Strong rec jjpcondor · 2012-09 · Stack Overflow · on “Why Immediately-Invoked Function Expression (IIFE) are different from Self-Executing Anonymus Functions?”
I have found an excellent explanation given by Mark Dalgleish here: [this video] – 1) IIFE do not execute them selves, they are invoked like any other function – 2) IIFE do not have to be anonimous, it is only important that they are function expressions.
Cites user2015338 · 2013-01 · Stack Overflow · on “Callback this context”
Thank you phant0m, I was watching this video about closures at the same time [this video] @10min53sec he says: A closure is created when a function is returned from another function, retaining its original scope. This is the reason why I asked :)
Cites Nav · 2013-05 · Stack Overflow · on “Is a function return necessary to be called a Closure”
Hey i came across this video on youtube [this video] which basically explains IIFEs and closures. But what I am not understanding is whether i need to return a function in order to call it a closure. E.x. function a() { var i = 10; function b() { alert(i); } } in this case can i call it a closure as it is accessing the 'i' variable from the outer function's scope or do i need to return the function like this return function b(){alert(i);}
Cites Adi · 2015-06 · Stack Overflow · on “What is the difference between function declaration Vs. definition in JavaScript?”
To add some context... At about 2:20 on this video [this video] the author makes this statement... "Parentheses around the function that causes the parser to treat it not as a function declaration but as a definition". Hence my curiosity if there is any difference between declaration Vs. definition? @Bergi