Created
March 3, 2011 23:30
-
-
Save tanem/853855 to your computer and use it in GitHub Desktop.
This file contains 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: | |
function Person(name) { | |
this.name = name; | |
} | |
var thomas = new Person('Thomas'); | |
var amy = new Person('Amy'); | |
console.log(thomas.name); // --> "Thomas" | |
// 2. Add a getName() method to all Person objects, that outputs | |
// the persons name. | |
Person.prototype.getName = function() { | |
console.log(this.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. | |
// console.log(typeof thomas.getName === 'function' && typeof amy.getName === 'function'); --> true | |
delete Person.prototype.getName; | |
// console.log(typeof thomas.getName === 'function' && typeof amy.getName === 'function'); --> false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment