使用
例如存在如下函数:
1 | int sum(int a, int b, {List<int>? more}) { |
可以直接通过:
1 | sum(1, 2, more: [3, 4, 5]); |
也可以通过:
1 | Function.apply(sum, [1, 2], {#more: [3, 4, 5]}); |
性能差距
测试代码:
1 | int sum(int a, int b, {List<int>? more}) { |
使用如下代码编译:
1 | dart compile exe test.dart |
测试结果:
1 | ➜ test ./test.exe |
为了防止编译器潜在的优化,我们可以使用如下代码:
1 | void main() { |
此时结果:
1 | ➜ test ./test.exe |