728x90
index.js
class UserStorage {
loginUser(id, password, onSuccess, onFailure) {
setTimeout(() => {
if (
(id === "ํ๊ธธ๋" && password === "์๋ฒ์ง") ||
(id === "ํฉ์ง์ด" && password === "์ฒญ์ฐ๋ฆฌ")
) {
onSuccess(id);
} else {
onFailure(new Error("not found"));
}
}, 2000);
}
getRoles(user, onSuccess, onFailure) {
setTimeout(() => {
if (user === "ํ๊ธธ๋") {
onSuccess({
name: "ํ๊ธธ๋",
role: "์๋ฒ์ง๋ฅผ ์๋ฒ์ง๋ผ ๋ถ๋ฅด์ง๋ ๋ชปํ๊ณ ...",
});
} else {
onFailure(new Error("no access!!!"));
}
}, 3000);
}
}
const userStorage = new UserStorage();
const id = prompt("๋์ ์ด๋ฆ์");
const password = prompt("๋น๋ฐ๋ฒํธ๋?");
userStorage.loginUser(
id,
password,
(user) => {
userStorage.getRoles(
user,
(userWithRole) => {
alert(`Hello ${userWithRole.name}, ๋์ ๋ช
๋์ฌ ${userWithRole.role}`);
},
(error) => {
console.log(error);
}
);
},
(error) => {
console.log(error);
}
);
728x90
'Javascript > Javascript' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
| ์๋ฐ์คํฌ๋ฆฝํธ ๋ฐ๋ณต๋ฌธ (0) | 2022.04.14 |
|---|---|
| [๋๋ฆผ์ฝ๋ฉ ์๋ฐ์คํฌ๋ฆฝํธ] ๋น๋๊ธฐ promise (0) | 2022.04.13 |
| [์๋ฐ์คํฌ๋ฆฝํธ ์ค๊ธ] call, apply, bind (0) | 2022.03.28 |
| [๊ธฐ์ด ์๋ฐ์คํฌ๋ฆฝํธ] ๋๋ฆผ์ฝ๋ฉ by ์๋ฆฌ๋ ์๋ฐ์คํฌ๋ฆฝํธ ๊ธฐ์ด ๊ฐ์ (ES5+) ์๋ฆฌ์ฆ ์ ์ฃผํ ๊ธฐ๋ก (0) | 2022.03.25 |
| [์ค๊ธ ์๋ฐ์คํฌ๋ฆฝํธ] ์ฌ๋ณผ (0) | 2022.03.24 |