Prioritize parameters in transferring internal variables of functions.
You are advised to modify the code to comply with the ArkTS Performant Programming Practices.
// code-linter.json5
{
"rules": {
"@performance/hp-performance-no-closures": "suggestion",
}
} let arr = [0, 1, 2];
function foo(array: Array<number>): number {
// Whenever possible, use parameters to transfer arr.
return array[0] + array[1];
}
foo(arr); let arr = [0, 1, 2];
function foo() {
// Whenever possible, use parameters to transfer arr.
return arr[0] + arr[1];
}
foo(); plugin:@performance/all
For details about how to configure Code Linter check rules, see Code Linter.