various-ways-to-invoke-functions-in-dart
About various-ways-to-invoke-functions-in-dart
A Dart skill covering several ways to invoke functions, including mixed positional and named arguments, `.call`, and `Function.apply`. It is for developers learning function-call syntax and its trade-offs.
Key features
- 01Mix positional and named arguments
- 02Invoke a function with `.call`
- 03Dynamic invocation with `Function.apply`
- 04Notes on JavaScript compilation impact
Use cases
- 01Call functions with positional and named parameters
- 02Invoke a referenced function dynamically
Install
Copy the command and run it in a terminal.
npx skills add https:/ / github.com/ rodydavis/ skills --skill various-ways-to-invoke-functions-in-dartAfter installing, type/various-ways-to-invoke-functions-in-dartin Claude Code to confirm it loaded.
Details
From the project READMEVarious Ways to Invoke Functions in Dart
There are multiple ways to call a Function in Dart.
The examples below will assume the following function:
void myFunction(int a, int b, {int? c, int? d}) {
print((a, b, c, d));
}
But recently I learned that you can call a functions positional arguments in any order mixed with the named arguments. 🤯
myFunction(1, 2, c: 3, d: 4);
myFunction(1, c: 3, d: 4, 2);
myFunction(c: 3, d: 4, 1, 2);
myFunction(c: 3, 1, 2, d: 4);
In addition you can use the .call operator to invoke the function if you have a reference to it:
myFunction.call(1, 2, c: 3, d: 4);
You can also use Function.apply to dynamically invoke a function with a reference but it should be noted that it will effect js dart complication size and performance:
Function.apply(myFunction, [1, 2], {#c: 3, #d: 4});
All of these methods print the following:
(1, 2, 3, 4)