stlapview: fix closure let-capture

pull/2760/head
Rob Pilling 2023-05-16 23:35:37 +01:00
parent 7bd8d4701a
commit ca9bae78af
1 changed files with 4 additions and 1 deletions

View File

@ -95,7 +95,10 @@ function showMainMenu() {
}; };
for (let lapFile of LAP_FILES) { for (let lapFile of LAP_FILES) {
mainMenu[fileNameToDateString(lapFile)] = () => view(lapFile); // `let` variables in JS have special behaviour in loops,
// where capturing them captures that instance of the variable,
// but for espruino we need to do a slightly older trick:
mainMenu[fileNameToDateString(lapFile)] = ((lapFile) => () => view(lapFile))(lapFile);
} }
if (LAP_FILES.length == 0) { if (LAP_FILES.length == 0) {