Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sergiopichardo/ab8b6943a12cf619f1cd4140769f11a0 to your computer and use it in GitHub Desktop.
Save sergiopichardo/ab8b6943a12cf619f1cd4140769f11a0 to your computer and use it in GitHub Desktop.
using the bind method to permanently bind a method to an object.
function fetchData() {
let sergiosTasks = {
tasks: ['study oop javascript', 'prepare for sysops exam', 'read linux book', 'write article'],
getTasks() {
console.log('Today I have to:')
this.tasks.forEach((task, index) => {
console.log(`(${index + 1}) ${task}`);
})
}
}
logTasks(sergiosTasks.getTasks.bind(sergiosTasks));
}
function logTasks(callback) {
callback();
}
fetchData();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment