A closure is a function inside another, that reference a variable in the outer function.
function showClosure() { var name = "Victor"; this.getNameWithClosure = function() { return name; } } var closureExample = new showClosure(); closureExample.getNameWithClosure();
The variable "name" isn't garbage collected because of the reference, that keep it within a closure. It is a free variable, that is a variable still alive after the function in which it is defined has completed.
Copyright © 2013 Welcome to the website of Davis Fiore. All Rights Reserved.