Skip to content

Instantly share code, notes, and snippets.

@rehasantiago
Created March 26, 2022 18:22
Show Gist options
  • Save rehasantiago/7e464e05faf7405d7bbb63aa9ca1ce67 to your computer and use it in GitHub Desktop.
Save rehasantiago/7e464e05faf7405d7bbb63aa9ca1ce67 to your computer and use it in GitHub Desktop.
Revealing the mystery behind this - https://readosapien.com/revealing-the-mystery-behind-this
let song1 = {
song: 'Blank Space',
getSong: function() {
console.log(this.song);
}
};
let song2 = {
song: 'Levitating',
};
let song3 = {
song: 'Uptown Funk'
}
let song = song1.getSong.bind(song2);
song(); // Levitating
console.log(song.call(song3)); // Levitating
console.log(song.apply(song3)); // Levitating
console.log(song.bind(song3)()); // Levitating
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment