Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Define a simple Being prototype with isLiving(), die(), and _living starting
- // off as true.
- function Being() {}
- Being.prototype._living = true;
- Being.prototype.isLiving = function() { return this._living; };
- Being.prototype.die = function() { this._living = false; };
- // Define a simple Person prototype which is constructed with a gender.
- function Person(gender) { this._gender = gender; }
- // Make the Person prototype inherit from the Being prototype.
- Person.prototype = new Being();
- // Add a getter for gender only to the Person prototype.
- Person.prototype.getGender = function() { return this._gender; }
- // Test out a being.
- var being1 = new Being();
- console.log('Does being1 start off living?', being1.isLiving());
- being1.die();
- console.log('After executing being1.die() is being1 still living?', being1.isLiving());
- console.log('Does being1 have a getGender function?', 'function' == typeof being1.getGender);
- // Test out a person.
- var person1 = new Person('Male');
- console.log('Does person1 start off living?', person1.isLiving());
- person1.die();
- console.log('After executing person1.die() is person1 still living?', person1.isLiving());
- console.log('Does person1 have a getGender function?', 'function' == typeof person1.getGender);
- console.log("What is person1's gender?", person1.getGender());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement