프로미스 : 비동기 처리를 추상화한 객체 -> 비동기 처리 후 다음 처리를 실행하기 위한 용도

 

순서 보장을 위해 쓰던 콜백 지옥을 대체

 

다음 동작을 위해 아래의 상태로 존재

1. Fulfilled : 성공

2. Rejected : 실패 - 에러

3. Pending : 진행중

 

var promise = new Promise(function(resolve, reject){ ... });

resolve : fulfilled 상태가 될 때 실행

reject : rejected 상태가 될 때 실행

-- 두 함수 모두 프로미스를 종료시키며 인자값을 전달할 수 있다

var promise = new Promise(function(resolve,reject){
	setTimeout(function(){
		console.log("Hello");
        resolve("World");
    },1000 );
});

promise.then(function(response){
	console.log(response);
})
var promise = new Promise(function(resolve,reject) {
	setTimeout(function(){
    	console.log("Hello");
        reject("World");
    },1000);
});

promise.then(function(response){
		console.log("Success!");
    }).catch(function(error){
    	console.log(error);
	}).finally(()=> {
    	console.log("finally!");
    });

 

 

 

현재 모던 자바스크립트 = ES2015부터 나온 버전으로 통용된다.

 

자바스크립트는 매년 변하고 브라우저 호환성 이슈  발생 -> 번들러 탄생하게 됐다.

 

(여러 자바스크립트+다른 요소들을 하나의 자바스크립트, 다른 요소로 합쳐주는 개념이다)

 

TypeScript?

--> 자바스크립트 + 추가기능을 가진다

--> 데이터에 설명을 붙히는 개념

 

let x = 100;

이 변수에서 자바스크립트는 따로 자료형을 지정하지 않기 때문에 

값이 무엇인지 정확하게 설명하지 않음

--> 타입스크립트가 이를 해결

 

let x:number = 100;

-->number라고 알려줌

 

type Centimeter = number;

let height:Centimeter = 176;

--> height는 숫자인 센치미터로 표현됨

 

type RainbowColor = 'red' | 'orange' | 'yellow'

let color : RainbowColor = 'yellow';

--> 다른 색이 들어가면 타입스크립트에서 에러는 냄

 

=====타입스크립트가 트랜스 파일러이기 때문에 가능하다 =====

 

 

 

 

 

+ Recent posts