-
-
Save yukeehan/7ef977c5e83561adaf89e5f211c26e50 to your computer and use it in GitHub Desktop.
bind
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* let dog = { | |
sound: 'woof', | |
talk: function(){ | |
console.log(this.sound); | |
} | |
} | |
const Talk = dog.talk.bind(dog); | |
Talk(); */ | |
function talk() { | |
console.log(this.sound) | |
} | |
let boromir = { | |
blabber: talk, | |
sound: 'one' | |
} | |
let gollum = { | |
jabber: boromir.blabber, | |
sound: 'Mymymy' | |
} | |
gollum.jabber(); | |
/* boromir.speak = talk.bind(boromir); | |
let blabber = boromir.speak; | |
blabber(); | |
*/ | |
/* let talkBoundToBoromir = talk.bind(boromir); | |
talkBoundToBoromir(); | |
talk(); */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment