Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var Person = (function () {
- function Person(name, age, isMale, children) {
- if (this.constructor === Person) {
- throw new Error('Cannot instantiate abstract class Person.');
- }
- this.setName(name);
- this.setAge(age);
- this.setIsMale(isMale);
- this.setChildren(children);
- }
- Person.prototype.getName = function() {
- return this._name;
- };
- Person.prototype.setName = function(name) {
- if(typeof (name) != 'string') {
- throw new Error('name should be a string.');
- }
- if (!name) {
- throw new Error('name cannot be empty.');
- }
- this._name = name;
- };
- Person.prototype.getAge = function() {
- return this._age;
- };
- Person.prototype.setAge = function(age) {
- if(! isInteger(age)) {
- throw new Error('age should be an integer number.');
- }
- this._age = age;
- };
- Person.prototype.getIsMale = function() {
- return this._isMale;
- };
- Person.prototype.setIsMale = function(isMale) {
- if(typeof (isMale) != 'boolean') {
- throw new Error('isMale should be a boolean value.');
- }
- this._isMale = isMale;
- };
- Person.prototype.getChildren = function() {
- return this._children;
- };
- Person.prototype.setChildren = function(children) {
- if(! isInteger(children)) {
- throw new Error('children should be an integer number.');
- }
- this._children = children;
- };
- Person.prototype.toString = function () {
- return 'Name: ' + this.getName() + 'Age: ' + this.getAge() + 'IsMale: ' + this.getIsMale() + 'Children: ' + this.getChildren();
- };
- return Person;
- }());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement