Skip to main content
deleted 6 characters in body
Source Link

The code already uses some features like the const and let keywords and template literals.

Another ES-6 feature that could be used is the for...of loop to simplify blocks like this:

for (let i = 0; i < items.length; i++) {
    movies += template
        .replace('{title}', items[i].title)
        .replace('{description}', items[i].description);
}

To this:

for (const item of items) {
    movies += template
        .replace('{title}', item.title)
        .replace('{description}', item.description);
}

The error handler could be simplified using a partially applied function, to avoid an extra function call - i.e.

error: function(error) {
       onError(movieList);
   }

Can be simplified to:

error: onError.bind(null, movieList)

The code already uses some features like the const and let keywords and template literals.

Another ES-6 feature that could be used is the for...of loop to simplify blocks like this:

for (let i = 0; i < items.length; i++) {
    movies += template
        .replace('{title}', items[i].title)
        .replace('{description}', items[i].description);
}

To this:

for (const item of items) {
    movies += template
        .replace('{title}', item.title)
        .replace('{description}', item.description);
}

The error handler could be simplified using a partially applied function, to avoid an extra function call - i.e.

error: function(error) {
       onError(movieList);
   }

Can be simplified to:

error: onError.bind(null, movieList)

The code already uses some features like the const and let keywords and template literals.

Another ES-6 feature that could be used is the for...of loop to simplify blocks like this:

for (let i = 0; i < items.length; i++) {
    movies += template
        .replace('{title}', items[i].title)
        .replace('{description}', items[i].description);
}

To this:

for (const item of items) {
    movies += template
        .replace('{title}', item.title)
        .replace('{description}', item.description);
}

The error handler could be simplified using a partially applied function, to avoid an extra function call - i.e.

error: function(error) {
    onError(movieList);
}

Can be simplified to:

error: onError.bind(null, movieList)
Source Link

The code already uses some features like the const and let keywords and template literals.

Another ES-6 feature that could be used is the for...of loop to simplify blocks like this:

for (let i = 0; i < items.length; i++) {
    movies += template
        .replace('{title}', items[i].title)
        .replace('{description}', items[i].description);
}

To this:

for (const item of items) {
    movies += template
        .replace('{title}', item.title)
        .replace('{description}', item.description);
}

The error handler could be simplified using a partially applied function, to avoid an extra function call - i.e.

error: function(error) {
       onError(movieList);
   }

Can be simplified to:

error: onError.bind(null, movieList)