[230427] 자바스크립트 실습

윤지수·2023년 4월 27일
0
post-thumbnail

💻 vending machine 실습

https://github.com/yoonmallang22/vending-machine

  • JavaScript modules

자바스크립트를 모듈처럼 기능들로 분리해서 편하게 합칠 수 있도록 만들어주는 문법

node.js, Webpack, Babel 등을 사용하여 모듈 사용
최신 브라우저가 기본적으로 모듈 기능을 지원하기 시작

모듈 밖으로 항목을 내보내는 export

// export default: '해당 모듈엔 개체가 하나만 있다'
export default ColaGenerator;

모듈에서 내보낸 기능을 사용할 수 있도록 사용할 스크립트로 가져오는 import

import ColaGenerator from "./classes/colaGenerator.js";

<script> 요소에 type="module" 써주지 않으면 모듈 기능을 쓸 수 없음

  • 클래스 constructor 함수: 인스턴스 만들 때 자동으로 실행됨

  • new Intl.NumberFormat().format(number)

Intl 객체: 각 언어에 맞는 문자비교, 숫자, 시간, 날짜비교를 제공하는 ECMAScript 국제화 API를 위한 이름공간
Intl.NumberFormat: 언어에 맞는 숫자 서식을 지원하는 객체의 생성자
Intl.NumberFormat.prototype.format(): formats a number according to the locale and formatting options of this Intl.NumberFormat object

new Intl.NumberFormat("en-US").format(1234567891234567891);
// 1,234,567,891,234,568,000
  • 탑레벨 await: 최상위 모듈에서 실행되는 await

You can use the await keyword on its own (outside of an async function) at the top level of a module.

  • forEach는 순환을 중간에 멈출 방법이 없음

0개의 댓글