Guest User

Untitled

a guest
Jan 22nd, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. // 1. Write a class to support the following code:
  2.  
  3. var Person = function(name){
  4. this.name = name;
  5. }
  6.  
  7.  
  8. var thomas = new Person('Thomas');
  9. var amy = new Person('Amy');
  10.  
  11. thomas.name // --> "Thomas"
  12.  
  13.  
  14. // 2. Add a getName() method to all Person objects, that outputs
  15. // the persons name.
  16. Person.prototype.getName = function(){
  17. return this.name;
  18. }
  19. thomas.getName(); // --> "Thomas"
  20.  
  21. // 3. Write a statement that calls Thomas's getName function,
  22. // but returns "Amy".
  23. thomas.getName.call(amy)
  24.  
  25. // 4. Remove the getName() method from all Person objects.
  26. delete Person.prototype.getName;
Add Comment
Please, Sign In to add comment