fac19 / week2-guardians

https://fac19.github.io/week2-guardians/
0 stars 0 forks source link

ES5 -> ES6. => Fat Arrows FTW! => #38

Open redahaq opened 4 years ago

redahaq commented 4 years ago

You have a mix of ES5 and ES6 syntax going on, which is totally normal at this stage, but it would be great to see you transition to using ES6 from next week.

I can see you're using ES6 when using the forEach higher order function, and with Promises, which didn't really exist before ES6.

Eg your function 'fetchRequest' can be refactored from

function fetchRequest(movieName) { fetch(https://api.themoviedb.org/3/search/movie?api_key=62b96ba98a33d55afab20dba768c38e2&query=${movieName}) etc

to:

fetchRequest = (movieName) => { fetch(https://api.themoviedb.org/3/search/movie?api_key=62b96ba98a33d55afab20dba768c38e2&query=${movieName}) etc **

** you don't need the parentheses around 'movieName' when you're only passing in one parameter, but I left it in there as you'll need the parens if you have more params

oliverjam commented 4 years ago

Sorry to be contrary, but I disagree 😅

It's pretty common to use function declarations for top-level functions and then arrow functions for callbacks, as you have (this is usually how I write code).

It's definitely good to be familiar with ES6 features, but they don't necessarily replace older stuff. Arrow functions aren't strictly better—they just look different (and have slightly different behaviour when it comes to this).