/    Sign up×
Community /Pin to ProfileBookmark

Comments on Closure

Hi,

Thanks to everyone for answering all my dumb questions about scope, and for helping me to overcome my Java mentality. I’ve been thinking a fair bit about scope and closure, and I wanted to write something that explained it succinctly and to my satisfaction, without any spooky stuff, so I wrote this:

[URL=”http://webofawesome.com/post/what-is-it-with-closure/”]webofawesome.com/post/what-is-it-with-closure/[/URL]

I’d really appreciate any thoughts or feedback…

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@goldfidgetauthorMay 09.2011 — The idea is that the scope object is created when a function is [B]run[/B]. The scope chain pointer is instantiated when a function is [B]created[/B], and is then immutable. When accessing a local variable the interpreter first looks in the scope object, then in the scope chain, then in the global scope.

This gives us closure...
Copy linkTweet thisAlerts:
@rnd_meMay 09.2011 — you are on the right track, but not 100% correct.

consider that unclosed local variables disappear. This implies that there is no fixed/local scope object that is inherited by "sub functions". otherwise, a lot of garbage would pile up. in short, only the reachable variables are closed, not all locals on the same object.

the spec makes it clear: "activation object"s perform the closure dirty-work.

read the spec for details.
Copy linkTweet thisAlerts:
@kiddomanMay 10.2011 — Thanks for sharing your information!
×

Success!

Help @goldfidget spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...