syntax - 这个语法是什么意思(...)
问题描述
我正在着手进行理性反应。在以下代码中:
let component = ReasonReact.statelessComponent("Component3");
let make = (~name, _children) => {
...component,
render: self => <input type_="checkbox" />,
};
我不明白第 3 行 (...) 的含义。当我删除它时,我收到一条错误消息:
The record field component can't be found.
If it's defined in another module or file, bring it into scope by:
- Annotating it with said module name: let baby = {MyModule.age: 3}
- Or specifying its type: let baby: MyModule.person = {age: 3}
解决方案
该表示称为扩展语法。这是在 ES6 中引入的。
MDN 文档中的定义和示例。链接在底部。
扩展语法允许在预期零个或多个参数(对于函数调用)或元素(对于数组字面量)的地方扩展诸如数组表达式或字符串之类的可迭代对象,或者在零个或多个参数的地方扩展对象表达式需要键值对(用于对象文字)
function sum(x, y, z) {
return x + y + z;
}
const numbers = [1, 2, 3];
console.log(sum(...numbers));
// expected output: 6
console.log(sum.apply(null, numbers));
// expected output: 6
更多详细信息:传播语法
推荐阅读
- reactjs - 如何设置反应材质ui选择组件高度的样式
- java - 从动态更新的数据表中删除元素
- python - 如何将 prometheus 指标直接推送到 VictoriaMetrics?
- python-3.x - 我忘记了我的超级用户用户名和密码。如何删除超级用户?
- javascript - 如果结束日期大于开始日期,如何拆分记录
- swiftui - UIDocumentPicker 对象的状态绑定问题
- java - 在java android中将自定义字体设置为Textview
- android - 在“jemise111 / react-native-swipe-list-view”上向左/向右滑动菜单项反应原生
- python - 将自定义 NER 模型添加到 spaCy 管道
- python - Python - 自动下载 csv 文件