Skip to content

Commit bfc17af

Browse files
committed
arrow function not recommended
1 parent 840d3a5 commit bfc17af

File tree

1 file changed

+4
-16
lines changed

1 file changed

+4
-16
lines changed

src/index.js

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,13 @@ const drink = {
1212
id: 'XAT5621',
1313
name: 'Root Beer',
1414
price: 99,
15-
getDrinkDetails() {
16-
return `Drink ${this.name} (${this.price})`
17-
}
18-
};
19-
20-
// PREVIOUS METHOD (babel)
21-
const oldDrink = {
22-
id: 'XAT5621',
23-
name: 'Root Beer',
24-
price: 99,
25-
getDrinkDetails: function () {
26-
return `Drink ${this.name} (${this.price})`
27-
}
15+
getDrinkDetails: () => `Drink ${this.name} (${this.price})`,
2816
};
2917

3018
console.log(drink.getDrinkDetails());
31-
console.log(oldDrink.getDrinkDetails());
3219

3320
/**
34-
* Two objects are never the same {} === {} is false
35-
* Unless you are comparing a byRef like drink === drinkReference
21+
* Using arrow functions breaks thge use of this
22+
* because in the arrowe function 'this' is determined by
23+
* ther calling method
3624
*/

0 commit comments

Comments
 (0)