Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. //Using Object.create
  2.  
  3. const personPrototypes = {
  4. greeting: function(){
  5. return `Hello there ${this.firstName} ${this.lastName}!`;
  6. },
  7. getsMarried: function(newLastName){
  8. this.lastName = newLastName;
  9. }
  10. }
  11.  
  12. const mary = Object.create(personPrototypes);
  13. mary.firstName = 'Mary';
  14. mary.lastName = 'Williams';
  15. mary.age = 30;
  16.  
  17. mary.getsMarried('Thompson');
  18.  
  19. console.log(mary.greeting());
  20.  
  21. const brad = Object.create(personPrototypes, {
  22. firstName: {value: 'Brad'},
  23. lastName: {value: 'Traversy'},
  24. age: {value: 36}
  25. });
  26.  
  27. console.log(brad);
  28. console.log(brad.greeting());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement