Created
July 30, 2021 01:56
-
-
Save sergiopichardo/ab8b6943a12cf619f1cd4140769f11a0 to your computer and use it in GitHub Desktop.
using the bind method to permanently bind a method to an object.
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
| 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