▪︎ Callback

▫︎ setTimeout

console.log(1);
setTimeout(() => console.log(2), 1000);
console.log(3);
// 1
// 3
// 2

▫︎ Callback Hell

lass UserStorage {
    loginUser(id, password, onSuccess, onError) {
        setTimeout(() => {
            if (id === "taehyun" && password === "1234") {
                onSuccess(id);
            } else {
                onError(new Error("존재하지 않는 계정입니다"));
            }
        }, 1000);
    }

    getRoles(user, onSuccess, onError) {
        setTimeout(() => {
            if (user === "taehyun") {
                onSuccess({ name: "taehyun", role: "crew" });
            } else {
                onError(new Error("권한이 없습니다."));
            }
        }, 1000);
    }
}
const userStorage = new UserStorage();

const id = prompt("ID를 입력해주세요");
const password = prompt("PW를 입력해주세요");

userStorage.loginUser(
    id,
    password,
    (id) => {
        userStorage.getRoles(
            id,
            (userWithRole) => {
                alert(
                    `Hello ${userWithRole.name}, 당신은 ${userWithRole.role}입니다.`
                );
            },
            (error) => console.log(error)
        );
    },
    (error) => console.log(error)
);

▪︎ Promise

▫︎ Producer