-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JavaScript Closure should be renamed just IIFE, because Closure and IIFE are two separate things. #700
Comments
Maybe in C there is no closure but in JavaScript "An IIFE is often used to create scope to encapsulate modules. Within the module there is a private scope that is self-contained and safe from unwanted or accidental modification. This technique, called the module pattern, is a powerful example of using closures to manage scope". http://www.sitepoint.com/demystifying-javascript-closures-callbacks-iifes/ |
that is incorrect concept. Isolating local variables inside of a local scope is IIFE and has nothing to do with a closure at all. |
I (sort of) agree with @jianlin here. There is typically no closures involved in registering an Angular service/controller/filter/directive/etc inside an IIFE (as suggested in this guide).
@MAustinMMDP, because it "is ofter used", it doesn't mean it is used every time. In that sense, the quote from http://www.sitepoint.com/demystifying-javascript-closures-callbacks-iifes/ is correct (in general) but irrelevant (in this particular case). |
actually the line on SitePoint really should say something like:
what it means is:
|
It should just say "Scope" |
https://github.com/johnpapa/angular-styleguide/blob/master/a1/README.md#style-y010
It mentions JavaScript Closures and IIFE. But using IIFE to create a local scope to prevent leak out to the global space has nothing to do with closures.
In C language, there is no closure, but we can use the same or similar technique just like IIFE to create a local scope and create variables that won't leak to the global space. So closures and IIFE are different concepts. What is being used is IIFE. Closure, it doesn't really matter if it exist or not in this case. It will be better if we use and propagate the correct concept around.
The text was updated successfully, but these errors were encountered: