Permalink
Browse files

Improves example

Show explicit vs. implicit return in .then() structure for subsequent
examples. The teachable moment here is that callback(prev) may not
return what you want it to return, so you may need to explicitly
return the pojo (or prev)
  • Loading branch information...
payne-chris-r
payne-chris-r committed May 8, 2017
1 parent cc55359 commit 7b10a13eac37beb5584d02a4a340f16f01b3f5ac
Showing with 6 additions and 4 deletions.
  1. +3 −2 README.md
  2. +1 −1 snippets/readJSON-promise-1.js
  3. +2 −1 snippets/readJSON-promise.js
@@ -110,7 +110,8 @@ const readJSON = function (filename) { // <-- look here
readJSON('./example.json') readJSON('./example.json')
.then((pojo) => { .then((pojo) => {
callback(pojo) // do something with the object delete pojo.key // modify object
return pojo // explicitly returns pojo
}) })
.catch((err) => { // handle error conditions .catch((err) => { // handle error conditions
console.error(err) console.error(err)
@@ -136,7 +137,7 @@ const readJSON = function (filename) {
} }
readJSON('./example.json') readJSON('./example.json')
.then(callback) // do something with the object .then(callback) // modify object --> returns what callback(prev) returns
.catch(console.error) // handle error conditions .catch(console.error) // handle error conditions
``` ```
<!-- end code block --> <!-- end code block -->
@@ -12,5 +12,5 @@ const readJSON = function (filename) {
} }


readJSON('./example.json') readJSON('./example.json')
.then(callback) // do something with the object .then(callback) // modify object --> returns what callback(prev) returns
.catch(console.error) // handle error conditions .catch(console.error) // handle error conditions
@@ -15,7 +15,8 @@ const readJSON = function (filename) { // <-- look here


readJSON('./example.json') readJSON('./example.json')
.then((pojo) => { .then((pojo) => {
callback(pojo) // do something with the object delete pojo.key // modify object
return pojo // explicitly returns pojo
}) })
.catch((err) => { // handle error conditions .catch((err) => { // handle error conditions
console.error(err) console.error(err)

0 comments on commit 7b10a13

Please sign in to comment.