diff options
author | Nick Van Doorn <vandoorn.nick@gmail.com> | 2018-10-10 18:56:58 -0700 |
---|---|---|
committer | Nick Van Doorn <vandoorn.nick@gmail.com> | 2018-10-10 18:56:58 -0700 |
commit | 5351d842be4856b9b9f2f4ea8caa05ee1a345eb6 (patch) | |
tree | d4d71e47906ad2a70ca07eb0e619eb0b961a13e1 | |
parent | 504bf34d115b60dc62740f481355970de8e51ea6 (diff) |
Make callback example more interesting
-rw-r--r-- | demos/4-anonymous-functions-callbacks.example.js | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/demos/4-anonymous-functions-callbacks.example.js b/demos/4-anonymous-functions-callbacks.example.js index 28cf6ab..23ea9c5 100644 --- a/demos/4-anonymous-functions-callbacks.example.js +++ b/demos/4-anonymous-functions-callbacks.example.js @@ -1,6 +1,10 @@ // Named function function getArticles() {} +// Named function that accepts +// a callback argument. +// We use this function to demo +// callback styles function getPlaylist(callback) { callback(null, ['Yandhi', 'oh wait shit nevermind']) } @@ -9,7 +13,13 @@ function getPlaylist(callback) { // Usually anonymous functions // are passed as arguments // to async functions -getPlaylist(function(err, res) {}) +getPlaylist(function(err, res) { + if (err) { + console.err(err) + } else { + console.log(res.join('👏🏼')) + } +}) // You can also name anonymous functions // and refer to it by name |