gpt4 book ai didi

javascript - 参数列表周围带有花括号的类构造函数/函数语法

转载 作者:行者123 更新时间:2023-11-29 17:55:19 25 4
gpt4 key购买 nike

<分区>

我最近看到这段代码:

class Foo {
constructor({
a,
b,
c = []
}) {
this.a = a;
this.b = b;
this.c = c;
console.log(this);
}
}
const foo = new Foo({
a: 1,
b: 2
});

但我从未见过用花括号包裹参数名称定义的参数。我的 linter 提示它,但代码工作正常,所以我认为它是有效的,因为它执行时没有错误。

我已经阅读了关于 class 的 MDN 文档, constructordefault arguments .但是,我没有在任何地方看到这种模式的描述(也许我错过了?)。

我要找的是什么,这个模式有名字吗,或者在某处有描述?

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com