-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// node.js style callbacks | ||
function1(args, (err, data) => { | ||
function2(args, (err, data) => { | ||
function3(args, (err, data) => { | ||
|
||
}); | ||
}); | ||
}); | ||
|
||
// promise style callbacks | ||
function1(args) | ||
.then(data => { | ||
return function2(args); | ||
}) | ||
.then(data => { | ||
return function3(args); | ||
}) | ||
.catch(err => { | ||
console.log(err); | ||
}); | ||
|
||
// async/await style | ||
try { | ||
let data1 = await function1(args); | ||
let data2 = await function2(args); | ||
let data3 = await function3(args); | ||
|
||
function4().then(data => { | ||
console.log('done'); | ||
}); | ||
} catch (e) { | ||
console.log(e); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
tips: | ||
- stay up-to-date on the latest version of node.js | ||
- make use of well supported npm modules | ||
- use a bundler for frontend things | ||
- use async/await, normal promises to defer | ||
- use strict equality === exclusively | ||
- don't block the event loop | ||
- avoid clever one-liners |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// normal | ||
switch (a) { | ||
case 1: | ||
console.log('one'); | ||
break; | ||
case 2: | ||
console.log('two'); | ||
break; | ||
default: | ||
console.log('none'); | ||
} | ||
|
||
// one liner | ||
console.log(a === 1 ? 'one' : a === 2 ? 'two' : 'none'); |