Skip to content

Commit 334e320

Browse files
committed
Fix preload plugin error callback variable scope
1 parent e5447ce commit 334e320

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

packages/jspsych/src/modules/plugin-api/MediaAPI.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -176,24 +176,24 @@ export class MediaAPI {
176176
return;
177177
}
178178

179-
for (var i = 0; i < images.length; i++) {
180-
var img = new Image();
181-
182-
img.onload = function () {
179+
for (let i = 0; i < images.length; i++) {
180+
const img = new Image();
181+
const src = images[i];
182+
img.onload = () => {
183183
n_loaded++;
184-
callback_load(img.src);
184+
callback_load(src);
185185
if (n_loaded === images.length) {
186186
callback_complete();
187187
}
188188
};
189189

190-
img.onerror = function (e) {
191-
callback_error({ source: img.src, error: e });
190+
img.onerror = (e) => {
191+
callback_error({ source: src, error: e });
192192
};
193193

194-
img.src = images[i];
194+
img.src = src;
195195

196-
this.img_cache[images[i]] = img;
196+
this.img_cache[src] = img;
197197
this.preload_requests.push(img);
198198
}
199199
}

0 commit comments

Comments
 (0)