Closures with variables
JavaScript
function person() {
var experience = 7;
function GetExperience() {
console.log(experience);
}
IncreaseExperience = function() {
experience++;
return GetExperience;
}
return IncreaseExperience;
}
var IncExp = person();
var GetExp = IncExp();
GetExp();
GetExp = IncExp();
GetExp(); //increments
GetExp = IncExp();
GetExp(); //increments again
var IncExp = person();
var GetExp = IncExp();
GetExp(); //fresh reference