const Direction = {
UP:'UP',
DOWN:'DOWN',
LEFT:'LEFT',
RIGHT:'RIGHT'
};
function sayDirection(direction){
switch(direction){
case Direction.UP :
console.log('we are going up');
break;
case Direction.DOWN :
console.log('we are going down');
break;
case Direction.LEFT :
console.log('we are going left');
break;
case Direction.RIGHT :
console.log('we are going right');
break;
}
};
sayDirection(Direction.UP);
//we are going up
각 케이스별 조건을 걸고 싶은 경우,
타입스크립트에서 자주 사용함.
'프론트엔드 공부 > javscript' 카테고리의 다른 글
배열구조분해할당(destructing) (0) | 2021.04.29 |
---|---|
객체구조분해할당(destructing) 예시 (0) | 2021.04.28 |
Map object (0) | 2021.04.28 |
reduce함수를 이용한 전체 합 구하기 (0) | 2021.04.28 |
04 array.map() (0) | 2021.04.27 |