Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. var dog = {
  2.  
  3. name: 'Killer',
  4. action: 'kills',
  5.  
  6. getDescription: function() {
  7. return 'A ' + this.name + ' which ' + this.action;
  8. }
  9.  
  10. }
  11.  
  12. var dog1Description = dog.getDescription(); // get a traditional dog description
  13.  
  14. var boundGetDescription = dog.getDescription.bind({ name: 'Hound', action: 'tracks' }); // get a description with modified values for its 'this' value
  15.  
  16. var dog2Description = boundGetDescription();
  17.  
  18. var dog3Description = dog.getDescription(); // get a traditional dog description
  19.  
  20. console.log(dog1Description); // A Killer which kills
  21. console.log(dog2Description); // A Hound which tracks
  22. console.log(dog3Description); // A Killer which kills
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement