mirror of
https://github.com/Stone-Red-Code/website.git
synced 2026-09-08 16:06:13 +02:00
content(docs): clean up unused parameter in code examples
This commit is contained in:
committed by
Jean-Philippe Sirois
parent
e4df60d22b
commit
1749ec3648
@@ -8,7 +8,7 @@ title: Simplifying Promises
|
|||||||
The first naive attempt, using new Promise for something that already returns a promise.
|
The first naive attempt, using new Promise for something that already returns a promise.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
function doAsync(number) {
|
function doAsync() {
|
||||||
return new Promise(function (resolve, reject) {
|
return new Promise(function (resolve, reject) {
|
||||||
doDatabase().then(function (dbResult) {
|
doDatabase().then(function (dbResult) {
|
||||||
otherDbFunction(dbResult).then(function (secondResult) {
|
otherDbFunction(dbResult).then(function (secondResult) {
|
||||||
@@ -23,7 +23,7 @@ Turns out you don't need new Promise if you're working with a function that
|
|||||||
already returns a promise, you can just return the original thing.
|
already returns a promise, you can just return the original thing.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
function doAsync(number) {
|
function doAsync() {
|
||||||
return doDatabase().then(function (dbResult) {
|
return doDatabase().then(function (dbResult) {
|
||||||
otherDbFunction(dbResult).then(function (secondResult) {
|
otherDbFunction(dbResult).then(function (secondResult) {
|
||||||
return secondResult + 10;
|
return secondResult + 10;
|
||||||
@@ -36,7 +36,7 @@ You also don't have to nest `.then` functions, the whole point of promises
|
|||||||
is that they allow you to chain them sequentially.
|
is that they allow you to chain them sequentially.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
function doAsync(number) {
|
function doAsync() {
|
||||||
return doDatabase()
|
return doDatabase()
|
||||||
.then(function (dbResult) {
|
.then(function (dbResult) {
|
||||||
return otherDbFunction(dbResult);
|
return otherDbFunction(dbResult);
|
||||||
@@ -51,7 +51,7 @@ you also don't have to create a new function just to pass in one
|
|||||||
variable, you can pass in the entire function itself to the then block
|
variable, you can pass in the entire function itself to the then block
|
||||||
|
|
||||||
```js
|
```js
|
||||||
function doAsync(number) {
|
function doAsync() {
|
||||||
return doDatabase()
|
return doDatabase()
|
||||||
.then(otherDbFunction)
|
.then(otherDbFunction)
|
||||||
.then(function (secondResult) {
|
.then(function (secondResult) {
|
||||||
@@ -63,7 +63,7 @@ function doAsync(number) {
|
|||||||
And you don't need those returns if you just have ES6 arrow functions
|
And you don't need those returns if you just have ES6 arrow functions
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const doAsync = (number) =>
|
const doAsync = () =>
|
||||||
doDatabase()
|
doDatabase()
|
||||||
.then(otherDbFunction)
|
.then(otherDbFunction)
|
||||||
.then((secondResult) => secondResult + 10);
|
.then((secondResult) => secondResult + 10);
|
||||||
|
|||||||
Reference in New Issue
Block a user