Skip to content

Instantly share code, notes, and snippets.

@quephird
Created March 9, 2012 18:33
Show Gist options
  • Save quephird/2007923 to your computer and use it in GitHub Desktop.
Save quephird/2007923 to your computer and use it in GitHub Desktop.
Exercise 8 for JavaScript Masters class
// 1. Write a class to support the following code:
var Person = function(name) {
this.name = name;
}
var thomas = new Person('Thomas');
var amy = new Person('Amy');
console.log(thomas.name);
console.log(amy.name);
// 2. Add a getName() method to all Person objects, that outputs
// the persons name.
Person.prototype.getName = function() {
return this.name;
}
console.log(thomas.getName());
console.log(amy.getName());
// 3. Write a statement that calls Thomas's getName function,
// but returns "Amy". (Don't change or redefine the getName
// function in any way.)
console.log(function() {thomas.getName(); return "Amy"; }()) ;
// 4. Remove the getName() method from all Person objects.
delete Person.prototype.getName;
console.log(thomas.getName());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment