Permalink
Browse files

Added Promises example

  • Loading branch information...
hparra committed Aug 31, 2016
1 parent ae9c007 commit f755ff9342a2680deba099ce10111bfecaa8369f
Showing with 33 additions and 0 deletions.
  1. +33 −0 javascript-style.md
View
@@ -60,6 +60,39 @@ if (myBoolean) {}
if (myBoolean === true) {}
```
Prefer `=>` when using Promises or callbacks.
Use indentation with Promises to improve readability:
```javascript
// OK
myFuncThatReturnsPromise()
.then(res => someTransform(res, 'something'))
.then(console.log)
.catch(console.error)
// OK
SomeStaticClass
.myFuncThatReturnsPromise()
.then(res => {
console.log(res)
return someTransform(res, 'something')
})
.then(console.log)
.catch(console.error)
// Avoid - `then` on same line
myFuncThatReturnsPromise().then(res => someTransform(res, 'something'))
.then(console.log)
.catch(console.error)
// Avoid - not using arrow and not properly indented
myFuncThatReturnsPromise().then(function (res) {
return someTransform(res, 'something')
})
.then(console.log)
.catch(console.error)
```
## Nice Things
```javascript

0 comments on commit f755ff9

Please sign in to comment.