Advertisement
Guest User

Solver DGE

a guest
Nov 13th, 2014
341
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var Person = (function () {
  2.     function Person(name, age, isMale, children) {
  3.         if (this.constructor === Person) {
  4.             throw new Error('Cannot instantiate abstract class Person.');
  5.         }
  6.         this.setName(name);
  7.         this.setAge(age);
  8.         this.setIsMale(isMale);
  9.         this.setChildren(children);
  10.     }
  11.  
  12.     Person.prototype.getName = function() {
  13.         return this._name;
  14.     };
  15.  
  16.     Person.prototype.setName = function(name) {
  17.         if(typeof (name) != 'string') {
  18.             throw new Error('name should be a string.');
  19.         }
  20.  
  21.         if (!name) {
  22.             throw new Error('name cannot be empty.');
  23.         }
  24.  
  25.         this._name = name;
  26.     };
  27.  
  28.     Person.prototype.getAge = function() {
  29.         return this._age;
  30.     };
  31.  
  32.     Person.prototype.setAge = function(age) {
  33.         if(! isInteger(age)) {
  34.             throw new Error('age should be an integer number.');
  35.         }
  36.  
  37.         this._age = age;
  38.     };
  39.  
  40.     Person.prototype.getIsMale = function() {
  41.         return this._isMale;
  42.     };
  43.  
  44.     Person.prototype.setIsMale = function(isMale) {
  45.         if(typeof (isMale) != 'boolean') {
  46.             throw new Error('isMale should be a boolean value.');
  47.         }
  48.  
  49.         this._isMale = isMale;
  50.     };
  51.  
  52.     Person.prototype.getChildren = function() {
  53.         return this._children;
  54.     };
  55.  
  56.     Person.prototype.setChildren = function(children) {
  57.         if(! isInteger(children)) {
  58.             throw new Error('children should be an integer number.');
  59.         }
  60.  
  61.         this._children = children;
  62.     };
  63.  
  64.  
  65.     Person.prototype.toString = function () {
  66.         return 'Name: ' + this.getName() + 'Age: ' + this.getAge() + 'IsMale: ' + this.getIsMale() + 'Children: ' + this.getChildren();
  67.     };
  68.  
  69.     return Person;
  70. }());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement