p 848

수빈·2023년 3월 13일
0
const get = (url, dd) => {
    const xhr = new XMLHttpRequest();
    xhr.open('GET', url);
    xhr.send();

    xhr.onload = () => {
        if (xhr.status === 200) {
            dd(JSON.parse(xhr.response));
        } else {
            console.error(`${xhr.status} ${xhr.statusText}`);
        }
    };
};

const url = 'https://jsonplaceholder.typicode.com';


get(`${url}/posts/7`, ({userId}) => {
    console.log(userId);
    get(`${url}/users/${userId}`, aa => {
        console.log(aa);
    });
});

// aa = JSON.parse(xhr.response)
function get(dd) {
    dd('인수');
};

get(function(aa) {
    console.log(aa);
});

// dd = function(aa) 이므로 aa = '인수'
// dd는 함수 이름을 나타낸다
// dd = function(aa) {console.log(aa);};

0개의 댓글