Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save paulstraw/855386 to your computer and use it in GitHub Desktop.

Select an option

Save paulstraw/855386 to your computer and use it in GitHub Desktop.
// 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(){
return this.name;
}
console.log(thomas.getName()); // --> "Thomas"
// 3. Write a statement that calls Thomas's getName function,
// but returns "Amy".
console.log(thomas.getName.call(amy));
// 4. Remove the getName() method from all Person objects.
console.log("getName" in Person.prototype);
delete Person.prototype.getName;
console.log("getName" in Person.prototype);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment