Last active
December 29, 2018 13:35
-
-
Save flavioribeirojr/4f705cd11cac6dda0edeebbe7566e3f1 to your computer and use it in GitHub Desktop.
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
class Cart { | |
constructor() { | |
this.cart = [] | |
} | |
onItemAddedToCart() { | |
alert(`The cart has ${this.cart.length} items`) | |
} | |
addItemToCart(item) { | |
new Promise((resolve, reject) => // Simulação de requisição http | |
setTimeout(() => { | |
this.cart.push(item) | |
resolve() | |
}, 500) | |
) | |
.then(this.onItemAddedToCart) | |
} | |
} | |
const cart = new Cart() | |
cart.addItemToCart('Notebook') // this.cart is undefined |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment