gpt4 book ai didi

reactjs - JavaScript 中的 "..."(3 个点)是什么?

转载 作者:行者123 更新时间:2023-12-03 13:56:19 25 4
gpt4 key购买 nike

我是从this post了解到这件事的。

function StoreMixin(...stores) { // what is "..."
var Mixin = {
getInitialState() {
return this.getStateFromStores(this.props);
},
componentDidMount() {
stores.forEach(store =>
store.addChangeListener(this.handleStoresChanged)
);
this.setState(this.getStateFromStores(this.props));
},
componentWillUnmount() {
stores.forEach(store =>
store.removeChangeListener(this.handleStoresChanged)
);
},
handleStoresChanged() {
if (this.isMounted()) {
this.setState(this.getStateFromStores(this.props));
}
}
};
return Mixin;
}

请用示例代码解释什么是“...”。谢谢!

最佳答案

在该示例中,...Rest parameter ,语法允许我们将无限数量的参数表示为数组。

它有点相似(或不相似:),但与 spread syntax 不同。 .

在您的示例中,内部的 stores 参数是一个数组。如果像 StoreMixin(1,2,3) 那样调用 function StoreMixin(...stores) ,则 stores 将是 [1 , 2, 3] 等等。

关于reactjs - JavaScript 中的 "..."(3 个点)是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49957500/

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