Using arrow functions to manage the this. function
bomoniyi
Posted on February 26, 2023
const userData = {
username: "Reed",
title: "JavaScript Programmer",
getBio() {
console.log(`User ${this.username} is a ${this.title}`);
},
askToFriend() {
setTimeout(() => {
console.log(`Would you like to friend ${this.username}?`);
}, 2000);
}
}
userData.askToFriend();
If you have a function in a function, use the arrow function to make sure the this. function still pulls from the above function (example in code above).
💖 💪 🙅 🚩
bomoniyi
Posted on February 26, 2023
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.