Skip to content

Instantly share code, notes, and snippets.

@wallin
Created September 16, 2011 17:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wallin/1222563 to your computer and use it in GitHub Desktop.
Save wallin/1222563 to your computer and use it in GitHub Desktop.
var Person = function (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');
console.log(thomas.name); // --> "Thomas"
// 2. Add a getName() method to all Person objects, that outputs
// the persons name.
console.log(thomas.getName()); // --> "Thomas"
// 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(thomas.getName.call(amy));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment