Skip to content

Instantly share code, notes, and snippets.

@pcast01
Created August 11, 2019 13:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pcast01/c94a9b59177784c50b41e336d4173a08 to your computer and use it in GitHub Desktop.
Save pcast01/c94a9b59177784c50b41e336d4173a08 to your computer and use it in GitHub Desktop.
var dwightSalary = (function() {
var salary = 60000;
function changeBy(amount) {
salary += amount;
}
return {
raise: function() {
changeBy(5000);
},
lower: function() {
changeBy(-5000);
},
currentAmount: function() {
return salary;
}
};
})();
alert(dwightSalary.currentAmount()); // $60,000
dwightSalary.raise();
alert(dwightSalary.currentAmount()); // $65,000
dwightSalary.lower();
dwightSalary.lower();
alert(dwightSalary.currentAmount()); // $55,000
dwightSalary.changeBy(10000) // TypeError: undefined is not a function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment