什么是"..."(3个点)在javascript中? [英] What is "..." (3 dots) in javascript?

查看:34
本文介绍了什么是"..."(3个点)在javascript中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从了解了这件事这篇文章.

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;
}

请通过示例代码解释什么是"...".谢谢!

Please kindly explain what is "...", with example code. Thanks!

推荐答案

在该示例中, ...

In that example, the ... is a Rest parameter, a syntax allows us to represent an indefinite number of arguments as an array.

它有点相似(或不相似:),但与

It is somewhat similar (or not :), but it's not the same as the spread syntax.

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

In your example, the stores argument inside is an array. If function StoreMixin(...stores) is called like StoreMixin(1,2,3) then stores will be [1, 2, 3] and so on.

这篇关于什么是"..."(3个点)在javascript中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆