//类新特性
class User {
static name = '张三';
static #age = 10;
static {
this.name = '李四';
this.#age = 20;
}
static getAge() {
return User.#age;
}
}
User.name = '王五';
console.log('name', User.name);
// User.#age
console.log('age', User.getAge());
//2 at方法 用于访问数组/字符串某个位置的值
const arr2 = [1, 2, 3, 4];
let p1 = arr2.at(1);
console.log('p1', p1);
let p2 = arr2.at(-1);
console.log('p2', p2);
let s2 = 'hello'.at(-2);
console.log('s2', s2);
//3 Object.hasOwn() 检查对象是否拥有指定的自有属性(不检查原型链)
const obj3 = { prop: '1' };
let hasOwn = Object.hasOwn(obj3, 'prop');
console.log('hasOwn', hasOwn);