ES11
私有属性
私有属性只允许在类的内部调用,不允许在
在类中,使用#变量名定义私有属性
class Person {
name;
#age;
#weight;
constructor(name, age, weight) {
this.name = name;
this.#age = age;
this.#weight = weight;
}
intro() {
console.log(this.name);
console.log(this.#age);
console.log(this.#weight);
}
}
const gril = new Person('rose', 88, '100kg');
console.log(gril.name);
console.log(gril.#age);
console.log(gril.#weight);
通过类内部方法调用私有属性
class Person {
name;
#age;
#weight;
constructor(name, age, weight) {
this.name = name;
this.#age = age;
this.#weight = weight;
}
intro() {
console.log(this.name);
console.log(this.#age);
console.log(this.#weight);
}
}
const gril = new Person('rose', 88, '100kg');
gril.intro();
Promise.allSettled
进行批量异步任务的执行,需要获得所有异步任务的结果则使用allSettled,需要全部异步任务都执行成功则使用all。
allSettled
Promise.allSettled接受一个Promise对象的数组;返回的也是Promise对象,永远是成功的状态,成功的值是数组里面的每一个Promise对象的状态和结果。
const p1 = new Promise(