Skip to content

Instantly share code, notes, and snippets.

@TPei
Created February 17, 2015 15:58
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 TPei/b24d7b20ecda17031fa7 to your computer and use it in GitHub Desktop.
Save TPei/b24d7b20ecda17031fa7 to your computer and use it in GitHub Desktop.
Person
var Person = function() {
var name;
var age;
var savings = 0.0;
this.getName = function() {
return name;
};
this.setName = function(value) {
if (typeof value !== "string") {
throw "Argument must be a string";
}
name = String(value);
};
this.getAge = function() {
return age;
};
this.setAge = function(value) {
var newVal = parseInt(value);
if (isNaN(newVal) || (typeof value !== "number") || newVal !== value) {
throw "Argument must be an Integer";
}
age = value;
};
this.hasEnoughSavings = function(value) {
value = parseInt(value);
if (isNaN(value)) {
throw "Argument must be a Number";
}
return savings >= value;
};
this.givePaycheck = function() {
savings += 100.0;
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment