Guest User

Untitled

a guest
Sep 11th, 2012
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  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.  
  16. Person.prototype.getName = function() {
  17. return this.name
  18. }
  19.  
  20. thomas.getName() // --> "Thomas"
  21.  
  22. // 3. Write a statement that calls Thomas's getName function,
  23. // but returns "Amy". (Don't change or redefine the getName
  24. // function in any way.)
  25.  
  26. thomas.getName.call(amy);
  27.  
  28.  
  29. // 4. Remove the getName() method from all Person objects.
  30.  
  31. delete Person.prototype.getName;
  32.  
  33. thomas.getName();
Advertisement
Add Comment
Please, Sign In to add comment