我从那里了解到这件事这个帖子.
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;
}
请用示例代码解释什么是“...”。谢谢!
在该示例中,...
is a 其余参数,语法允许我们将无限数量的参数表示为数组。
它有点相似(或不相似:),但与扩展语法.
在你的例子中,stores
里面的参数是一个数组。如果function StoreMixin(...stores)
被称为像StoreMixin(1,2,3)
then stores
将[1, 2, 3]
等等。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)