这个问题在这里已有答案:
我正在全力以赴地做出反应。在以下代码中:
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}
该表示称为Spread Syntax。这是在ES6中引入的。
MDN Docs的定义和示例。链接在底部。
Spread语法允许在可能需要零个或多个参数(用于函数调用)或元素(用于数组文字)的位置扩展数组表达式或字符串等迭代,或者在零或更多位置扩展对象表达式键值对(对象文字)是预期的
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
更多细节:Spread Syntax