2022

class相关

  1. class X {
  2. #a; // 私有变量
  3. #b=1
  4. get b() { //get、set
  5. return this.#b;
  6. }
  7. static getBofX(x) {
  8. if(#b in x) return x.#b
  9. else return 'fail'
  10. }
  11. static { //静态块
  12. console.log('hello')
  13. }
  14. }
  15. try {
  16. }catch(e) {
  17. console.log(e);
  18. }

top-level await

  1. // users.js
  2. export const users = await fetch('/users/lists');
  3. // usage.js
  4. import { users } from "./users.js";
  5. // ✅ the module will wait for users to be fullfilled prior to executing any code
  6. console.log(users);

在web开发中,当同时使用事件监听和top-level await,会导致代码的执行顺序不确定。

Error cause

  1. async function f(url) {
  2. try {
  3. let x = await fetch(url);
  4. } catch(e) {
  5. throw new Error("fail", {cause: e})
  6. }
  7. }
  8. try {
  9. await f("x:x");
  10. } catch (e) {
  11. console.log(e, e.cause);
  12. }

参考

【1】https://www.ecma-international.org/
【2】https://yanhaijing.com/es5/#about