2015-01-18 15:36:36 -08:00
|
|
|
^title Fn Class
|
|
|
|
|
^category core
|
|
|
|
|
|
|
|
|
|
A first class function—an object that wraps an executable chunk of code.
|
|
|
|
|
[Here](../functions.html) is a friendly introduction.
|
|
|
|
|
|
|
|
|
|
### new **Fn**(function)
|
|
|
|
|
|
2015-02-22 12:34:32 -08:00
|
|
|
Creates a new function from... `function`. Of course, `function` is already a
|
|
|
|
|
function, so this really just returns the argument. It exists mainly to let you
|
|
|
|
|
create a "bare" function when you don't want to immediately pass it as a [block
|
|
|
|
|
argument](../functions.html#block-arguments) to some other method.
|
2015-01-18 15:36:36 -08:00
|
|
|
|
|
|
|
|
:::dart
|
|
|
|
|
var fn = new Fn {
|
|
|
|
|
IO.print("The body")
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-22 12:34:32 -08:00
|
|
|
It is a runtime error if `function` is not a function.
|
2015-01-18 15:36:36 -08:00
|
|
|
|
2015-01-23 20:33:05 -08:00
|
|
|
### **arity**
|
|
|
|
|
|
|
|
|
|
The number of arguments the function requires.
|
|
|
|
|
|
|
|
|
|
:::dart
|
|
|
|
|
IO.print(new Fn {}.arity) // 0.
|
|
|
|
|
IO.print(new Fn {|a, b, c| a }.arity) // 3.
|
|
|
|
|
|
2015-01-18 15:36:36 -08:00
|
|
|
### **call**(args...)
|
|
|
|
|
|
|
|
|
|
**TODO**
|