method .at()
字符串和数组新增 .at()
方法。
javascript
//1.数组
const names = ["abc", "cba", "nba"];
// 打印 'cba'
console.log(names.at(1));
// 打印 'nba'
console.log(names.at(-1));
// 2. 字符串
const str = "Hello Man";
// 打印 'e'
console.log(str.at(1));
// 打印 'n'
console.log(str.at(-1));
Object.hasOwn(obj, proKey)
用于判断一个对象中是否有某个自己的属性。ES13 准备使用 hasOwn
代替 hasOwnProperty
。 hasOwn
和 hasOwnProperty
的区别:
hasOwn
方法放在全局 'Object' 对象中(可防止重写),hasOwnProperty
放在自己的原型链上;- 当对象变量使用
Object.create(null)
创建时,原型链指向null
, 没有hasOwnProperty
,使用就会报错;
js
const info = Object.create(null);
info.name = "tom";
// 报错
info.hasOwnProperty("name");
New members of classes
js
class Person {
// 默认为 public
height = 1.88;
// ES13之前:约定私有属性 private 添加下划线前缀
_intro = "";
// 1. ES13之后:真正私有属性
#intro = "this is intro";
// 2. 静态属性(static)
static totalCount = 70;
// 3. 静态私有属性
static #maleTotalCount = 20;
// 静态代码块
static {
// 加载类时执行,且只执行一次,new 时不执行
console.log("hello world");
}
}