使用函数
A function type is a set of parameters that perform an operation.
函数语法
A Flux function literal 包含以下内容:
- 零个或多个参数,被括起来 (
())- 参数用逗号分隔
- 参数必须命名(没有位置参数)
- 可以为每个参数分配一个默认值,使用
=赋值运算符。没有默认值的参数需要用户输入,并被视为必需参数。
=>箭头运算符 用于将参数传递到函数体中。- 函数主体以定义函数操作并返回响应。
示例函数
// Function that returns the value 1
() => 1
// Function that returns the sum of a and b
(a, b) => a + b
// Function with default values
(x=1, y=1) => x * y
// Function with a block body
(a, b, c) => {
d = a + b
return d / c
}
定义函数
有关定义自定义函数的信息,请参阅 定义自定义函数。