JS Closures
by Kim Maida
JavaScript
function whenMeetingJohn(salutation) {
var greeting = salutation + ', John!';
function alertGreeting() {
alert(greeting);
}
return alertGreeting;
}
var atLunchToday = whenMeetingJohn('Hi');
atLunchToday(); // alerts "Hi, John!"
whenMeetingJohn('Whassup')(); // alerts "Whassup, John!"