Hazel Wu | 22'mm

Call Back Hell:Promise誕生

2018-10-02

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// first
function getRecipt(){
setTimeout( () => {
const recipeID = [523, 883, 432, 974];
console.log(recipeID);

setTimeout( id => {
const recipt = {
title: 'Fresh tomato',
publisher: 'Joans'
}
console.log(`${id}: ${recipt.title}`);

setTimeout(publisher => {
const recipe = {
title: 'Italian Pizza',
publisher: 'Joans'
}
console.log(recipe.publisher);
}, 1500, recipt.publisher);
}, 1000, recipeID[2]);
}, 1500);
}
getRecipt();

難管理
為了解決這樣的問題,於是誕生了「Promise」

閱讀量