Json
- AJAX : 웹페이지에서 동적으로 서버와 데이터를 주고 받을 수 있는 기술
- Json이란 : 데이터 전송의 가장 간편하고 간단한 방법.
- text를 기반해 가볍다.
- 대부분의 언어와 플랫폼에 사용이 가능하다. Json->다른 언어->Json의 작업이 매우 간단함.
Json->Object / Object -> Json
- Json.pars / stringfy
let json = Json.stringfy(true);
console.log(json); //true
//parse : string 를 받으면 Object로 변환
//stringfy : 어떤 타입을 받으면 String으로 변환
josn = JSON.srtingfy(['apple', 'banana']);
console.log(josn) // ["apple", "banana"] // json의 규격은 ""이다.
// Object to Json
cost rabbit = {
name : 'tori',
color : 'white',
size : 'null',
birthDate : new : date(),
jump : ()=> {console.log (`${name} van jump`}; //
},
};
const json - JSON.stringfy(rabbit);
console.log(rabbit) // ["name" : "tori" ......] 한 줄로 모든 내용이 다 표시된다.
//원하는 프로퍼티만 전달하기
json = JSON.stringfy(rabbit, [`name`]); = console.log(json); // {"name" : "tori"}
//Json to Object
const obj = JSON.parse(jsin);
console.log(obj); // 메소드 jump를 제외한 모든 내용이 한 줄로 나온다.
CallBack
console.log(1); //1
console.log(2); //2
console.log(3); //3
1,2,3//순서대로 나온다. 동기식이라고 한다.
console.log(1); //1
setTime()=>(console(2),1000);
console.log(3); //3
1,3,2 // 2가 1초 지연되어서 나온다. 비동기식이라고 한다.
//콜백의 두 종류 Synchrous(즉각, 동기식) / A Synchrous(나중, 비동기, 언제 될지 모름 )
//1
function printImmediately(print){
print();
}
printImmediately()=>console.log()
//2
printwiteDelay(()=>console.log('boom'), 2000);
//결과물 : 1 3 2 'boom' 순으로 나옴,
//콜백 지옥이란?
function callHell(A, B, C){
A(){
if(A==1){
b(){function c(){
function d(){
function e(){
}
}
}
} } }}
이런식으로 코드가 >모양으로 계속 callback를 하는 것을
콜백지옥이라고 한다.
가독성이 매우 떨어질 뿐만 아니라
디버그를 할 때 어디서 애러가 생기는지 파악하기도 너무나 어려워 진다.
'하루정리' 카테고리의 다른 글
2022.09.23 JavaScript - Promise (0) | 2022.09.23 |
---|---|
2022.09.21 공부 리눅스의 개념 및 유형 (0) | 2022.09.21 |
2022.09.14 Java Script 배열 함수 (0) | 2022.09.15 |
2022.09.13 JavaScript Array (0) | 2022.09.14 |
2022-09-07 하루 정리 JavaScpript Object (0) | 2022.09.07 |