const count = 1;
const a = new Promise( (resolve, reject) =>{
if( count == 1 ){
resolve() // 성공 했을때 ( then )
}
else if( count != 1 ){
reject() // 실패 했을때 ( catch )
}
})
a
.then( () => console.log( '성공' ) )
.catch( () => console.log( '실패') )
.finally( () => console.log('끝') )
// 성공
// 끝
const count = 1;
const a = new Promise( (resolve, reject) =>{
if(count == 1){
resolve(10)
}
else if(count != 1){
reject(-10)
}
})
a
.then( (count) => console.log( count ) )
.catch( (count) => console.log( count ) )
.finally( () => console.log('끝') )
[Javascript] async, await ( try, catch ) (0) | 2022.06.24 |
---|---|
[Javascript] Promise ( chaining, all, race ) (0) | 2022.06.20 |
[Javascript] class를 통한 상속( constructor, extends, super ) (0) | 2022.06.17 |
[Javascript] prototype을 통한 상속 (0) | 2022.06.15 |
[Javascript] function 메소드 ( call, apply, bind ) (0) | 2022.06.14 |