Lightning Components do not fully support ES6 syntax. However, a few important functions, such as Promise
and array utilities, such as filter, map, and reduce functions, have been found to work, as of the current version.
If you never need the capability to nest callbacks, your code can become difficult to debug and maintain. The following code snippet shows an example of nested callbacks (they are also commonly referred to as callback
hell):
getUsers(function () { getUserDetail(function () { getProductsPurchasedByUser(function() { getRecommendedProducts(function () { }); }); }); });
The Promise
API (https://developer.mozilla.Org/en-US/docs/Web/JavaScript/Guide/Using_promises) in JavaScript solves the problem of callback
hell by returning the object that can attach callbacks, rather than passing the callback
a the parameter.
The preceding code snippet for a nested callback
can be written...