From Wikipedia, the free encyclopedia: Closure (computer science)
In computer science, a closure is a function that is evaluated in an
(using an example from jQuery)
function SetClassOnHover(className){
$("td").hover(
function () {
$(this).addClass(className);
},
function () {
$(this).removeClass(className);
}
);
}
The closure comes into play when the variable className is used inside the scope of each function. When SetClassOnHover exits, both functions must retain a handle on className in order to access its value when the functions are called. That's what the closure enables.