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] 인덱스를 알려줌