Is it possible to gain access to the closure of a function?

That’s (one of) the purpose(s) of a closure – to keep information private. Since the function already has been executed its scope variables are no longer available from outside (and have never been) – only the functions executed in it’s scope (still) have access.

However you could give access via getters/setters.

You might want to take a look into Stuart Langridge’s talk about closures. Very recommendable are also Douglas Crockfords Explanations. You can do lots of fancy stuff with closures;)

Edit:
You have several options to examine the closure: Watch the object in the webdeveloper console or (as I do it often) return a debug-function which dumps out all the private variables to the console.

Leave a Comment