scrimba
JS Deep Dive
Classes
Fix Context Problems with .bind()
Go Pro!Bootcamp

Bootcamp

Study group

Collaborate with peers in your dedicated #study-group channel.

Code reviews

Submit projects for review using the /review command in your #code-reviews channel

To see this lesson you need to be logged in. Joining Scrimba is free and gives you access to 20+ courses.Sign up
Fix Context Problems with .bind()
AboutCommentsNotes
Fix Context Problems with .bind()
Expand for more info
index.js
run
preview
console
const isAuth = true;
const user = {
favorites: []
};

class Product {
constructor(name, price) {
this.name = name;
this.price = price;
}

handleFavoriteProduct() {
if (isAuth) {
this.favoriteProduct();
} else {
console.log("You must be signed in to favorite products!");
}
}

favoriteProduct() {
user.favorites.push(this.name);
console.log(`${this.name} favorited!`);
}
}
Console
index.html
-10:05