Skip to content

Instantly share code, notes, and snippets.

@cameronism
Created March 4, 2011 06:38
Show Gist options
  • Save cameronism/854272 to your computer and use it in GitHub Desktop.
Save cameronism/854272 to your computer and use it in GitHub Desktop.
function Person (name) {
this.name = name;
}
Person.prototype.getName = function () {
return this.name;
}
// 1. Write a class to support the following code:
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;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment