Last active
December 14, 2015 16:58
-
-
Save calebpowell/5118620 to your computer and use it in GitHub Desktop.
08_inheritance
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
| // 1. Write a class to support the following code: | |
| var Person = function(name) { | |
| this.name = name; | |
| this.getName = function(){ return this.name;} | |
| } | |
| var thomas = new Person('Thomas'); | |
| var amy = new Person('Amy'); | |
| thomas.name // --> "Thomas" | |
| // 2. Add a getName() method to all Person objects, that outputs | |
| // the persons name. | |
| thomas.getName() // --> "Thomas" | |
| // 3. Write a statement that calls Thomas's getName function, | |
| // but returns "Amy". | |
| thomas.getName.call(amy); | |
| // 4. Remove the getName() method from all Person objects. | |
| delete Person.prototype.getName; | |
| delete thomas.getName; | |
| delete amy.getName; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment