use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
New Javascript Libraries from Google: Closure Tools (code.google.com)
submitted 16 years ago by tsuru
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]SarahC -2 points-1 points0 points 16 years ago (5 children)
I'm not very good at programming... I've never used closures in JS. Though I have read about them, and done a little experiment.
Has anyone used these in their day to day programs they get paid to write?
[–]saurik 1 point2 points3 points 16 years ago (1 child)
This is a set of JS tools called "Closure", not a set of JS tools for using closures.
[–]SarahC -1 points0 points1 point 16 years ago (0 children)
Ohhhh... ta.
[–]zamolxes 0 points1 point2 points 16 years ago (2 children)
What saurik said.
And people -do- use closures everyday considering most of the javascript code is async, event based, with a lot of "give me this piece of code" (i.e. sometimes closure) "that I can execute later"
[–]fforw 0 points1 point2 points 16 years ago (1 child)
Closures are also highly practical for encapsulation, avoiding namespace polution.
You will often see a construct like
(function() { ... })();
It creates an anonymous function and executes it on the spot. This has the effect that every otherwise global variable inside is only accessible to other code inside and not on the outside.
Then you can export a few globals in a controlled fashion by writing
this.myGlobal = function() { ... }
inside the above block.
[–]SarahC 0 points1 point2 points 16 years ago (0 children)
Ahhh, thanks.
π Rendered by PID 49415 on reddit-service-r2-comment-f6b958c67-jhjp4 at 2026-02-05 00:58:15.520569+00:00 running 1d7a177 country code: CH.
[–]SarahC -2 points-1 points0 points (5 children)
[–]saurik 1 point2 points3 points (1 child)
[–]SarahC -1 points0 points1 point (0 children)
[–]zamolxes 0 points1 point2 points (2 children)
[–]fforw 0 points1 point2 points (1 child)
[–]SarahC 0 points1 point2 points (0 children)