2022
class相关
class X {
#a; // 私有变量
#b=1
get b() { //get、set
return this.#b;
}
static getBofX(x) {
if(#b in x) return x.#b
else return 'fail'
}
static { //静态块
console.log('hello')
}
}
try {
}catch(e) {
console.log(e);
}
top-level await
// users.js
export const users = await fetch('/users/lists');
// usage.js
import { users } from "./users.js";
// ✅ the module will wait for users to be fullfilled prior to executing any code
console.log(users);
在web开发中,当同时使用事件监听和top-level await,会导致代码的执行顺序不确定。
Error cause
async function f(url) {
try {
let x = await fetch(url);
} catch(e) {
throw new Error("fail", {cause: e})
}
}
try {
await f("x:x");
} catch (e) {
console.log(e, e.cause);
}
参考
【1】https://www.ecma-international.org/
【2】https://yanhaijing.com/es5/#about