Created
February 17, 2015 15:58
-
-
Save TPei/b24d7b20ecda17031fa7 to your computer and use it in GitHub Desktop.
Person
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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