Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 9th, 2012  |  syntax: None  |  size: 0.57 KB  |  hits: 19  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. // 1. Write a class to support the following code:
  2.  
  3. function Person(name) {
  4.   this.name = name;
  5. }
  6.  
  7. var thomas = new Person('Thomas');
  8. var amy = new Person('Amy');
  9.  
  10. thomas.name // --> "Thomas"
  11.  
  12. // 2. Add a getName() method to all Person objects, that outputs
  13. // the persons name.
  14.  
  15. Person.prototype.getName = function() {
  16.   return this.name;
  17. }
  18.  
  19. thomas.getName() // --> "Thomas"
  20.  
  21. // 3. Write a statement that calls Thomas's getName function,
  22. // but returns "Amy".
  23.  
  24. thomas.getName.apply(amy)
  25.  
  26. // 4. Remove the getName() method from all Person objects.
  27.  
  28. delete Person.prototype.getName