Skip to content

Instantly share code, notes, and snippets.

@solominh
Last active January 23, 2017 17:17
Show Gist options
  • Select an option

  • Save solominh/1dc5f6e02bd50bb08c2ca4d1c12ce8a0 to your computer and use it in GitHub Desktop.

Select an option

Save solominh/1dc5f6e02bd50bb08c2ca4d1c12ce8a0 to your computer and use it in GitHub Desktop.
// Catch function before then function
var a = Promise.reject('ErrorValue')
.catch((err) => {
console.log('Catch', 'PromiseValue', err)
})
.then((data) => {
console.log('Then', 'PromiseValue', data)
})
// Then function before catch function
var b = Promise.reject('ErrorValue')
.then((data) => {
console.log('Then', 'PromiseValue', data)
})
.catch((err) => {
console.log('Catch', 'PromiseValue', err)
})
// Return new promise value
var c = Promise.reject('ErrorValue')
.catch((err) => {
console.log('Catch', 'PromiseValue', err)
return 'NewPromiseValue'
})
.then((data) => {
console.log('Then', 'PromiseValue', data)
})
// Return new promise
var d = Promise.reject('ErrorValue')
.catch((err) => {
console.log('Catch', 'PromiseValue', err)
return Promise.resolve('ResolvedValue')
})
.then((data) => {
console.log('Then', 'PromiseValue', data)
})
// Multiple then functions
var e = Promise.reject('ErrorValue')
.catch((err) => {
console.log('Catch', 'PromiseValue', err)
return Promise.resolve('ResolvedValue')
})
.then((data) => {
console.log('Then1', 'PromiseValue', data)
})
.then((data) => {
console.log('Then2', 'PromiseValue', data)
})
.then((data) => {
console.log('Then3', 'PromiseValue', data)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment