Closures with objects
by Saksham Malhotra
JavaScript
function person() {
var prof = {
salary: 10000,
experience: 7
};
function GetExperience() {
console.log(prof.experience);
}
IncreaseExperience = function() {
prof.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