Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var dog = {
- name: 'Killer',
- action: 'kills',
- getDescription: function() {
- return 'A ' + this.name + ' which ' + this.action;
- }
- }
- var dog1Description = dog.getDescription(); // get a traditional dog description
- var boundGetDescription = dog.getDescription.bind({ name: 'Hound', action: 'tracks' }); // get a description with modified values for its 'this' value
- var dog2Description = boundGetDescription();
- var dog3Description = dog.getDescription(); // get a traditional dog description
- console.log(dog1Description); // A Killer which kills
- console.log(dog2Description); // A Hound which tracks
- console.log(dog3Description); // A Killer which kills
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement