-
Notifications
You must be signed in to change notification settings - Fork 0
/
callback_do_this.js
65 lines (60 loc) · 1.49 KB
/
callback_do_this.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// 재료
class UserStorage {
loginUser(id, passwd, onSuccess, onError) {
setTimeout( () => {
if(
(id === 'ellie' && passwd === 'dream') ||
(id === 'coder' && passwd === 'academy')
){
onSuccess(id);
} else {
onError(new Error('not Found'));
}
}, 1200);
}
getRoles(user, onSuccess, onError){
setTimeout( ()=> {
if(user === 'ellie'){
onSuccess({name:'ellie', role:'admin'});
} else {
onError(new Error('no access'));
}
}, 1000);
}
}
// 만들기..
var id = prompt('enter your id');
var passwd = prompt('and your password, also');
var userSto = new UserStorage();
userSto.loginUser(id, passwd,
(id)=>{
userSto.getRoles(id, ()=>console.log());
},
()=>{
console.log();
}
);
// 정답
const userStorage = new UserStorage();
const id = prompt('enter your id');
const passwd = prompt('and your password, also');
userStorage.loginUser(
id,
passwd,
user => {
userStorage.getRoles(
user,
userWithRole => {
alert(
`Hello ${userWithRole.name}, you have a ${userWithRole.role} role`
);
},
error => {
console.log(error);
}
);
},
error => {
console.log(error);
}
);