es2022 기능

dev.dave·2023년 7월 24일

Javascript

목록 보기
17/167

class Coffee {
#커피판매개수 = 0;
우유종류 = "저지방우유";

#make(원두) {
console.log(커피만드는 중...);
this.#커피판매개수++;
}

makeCoffee() {
this.#make("좋은원두");
}
}

new Coffee().makeCoffee(); //커피만드는중..

const coffee = new Coffee();

//coffee. 지금 #해논건 접근이 안된다.

////////////////////////////////////

//Top level await
//a.mjs
const res = await fetch("https://jsonplaceholder.typicode.com/user");
const user = res.json();
export { user };

//b.mjs
import { user } from "/a.mjs";
console.log(user);

////////////////////////////////

// Re-throw 시 cause로 에러 전달 , 왜냐면 정확한 에러 이유를 보여줌

function run() {
try {
a;
} catch {
throw new Error("failed...", { cause: err });
}
}

try {
run();
} catch (e) {
console.log("error", e.cause);
}

//////////////////////////////////////

//at 함수

const arr = [1, 2, 3, 4, 5];

//const lastValue = arr[arr.length - 1]; // 4

const lastValue = arr.at(-1); // 4
//at 쓰면 편해짐

///////////////////////////////////////

//indeices 정규표현식에서 쓰는것

const result = /(hello),(world)/d.exec("hello,world"); // ['hello,world']
result.indices[0]; // [0, 11]
result.indices[2]; // [6, 11] 인덱스를 알려줌

profile
🔥개인 메모 / 다른블로그 자료 참조 / 다른블로그 자료 퍼옴 (출처표기) /여기저기서 공부 했던 내용 개인메모 & 참고 / 개인 기록 용도 블로그 입니다.🔥

0개의 댓글