クライアント側の Web アプリケーションで ECMA スクリプト 6 の約束をサポートする必要があります。私はSpotify Web APIを使用しています。これは次のようになります
// track detail information for album tracks
spotifyApi.getAlbum('5U4W9E5WsYb2jUQWePT8Xm')
.then(function(data) {
return data.tracks.map(function(t) { return t.id; });
})
.then(function(trackIds) {
return spotifyApi.getTracks(trackIds);
})
.then(function(tracksInfo) {
console.log(tracksInfo);
})
.catch(function(error) {
console.error(error);
});
下位互換性のためにこれらをコールバックに変換できることはわかっていますが、それは非常に手間がかかり、コードがきれいに見えません。