From 37f3626e2bb4b954eef97f78aadff8feecdcf4fa Mon Sep 17 00:00:00 2001 From: paul jang Date: Sun, 22 Nov 2020 01:51:22 +0200 Subject: [PATCH] fix loadAsset function in example code 1. move `resolve(img)` in loadAsset function to the inside of the img.onload function to resolve the promise after the image is loaded 2. remove the async keyword of loadAsset because it is not that harmful but not yet necessary --- 6-space-game/2-drawing-to-canvas/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/6-space-game/2-drawing-to-canvas/README.md b/6-space-game/2-drawing-to-canvas/README.md index 015922e1..cd064a52 100644 --- a/6-space-game/2-drawing-to-canvas/README.md +++ b/6-space-game/2-drawing-to-canvas/README.md @@ -81,14 +81,14 @@ img.onload = () => { It's recommended to wrap the above in a construct like so, so it's easier to use and you only try to manipulate it when it's fully loaded: ```javascript -async function loadAsset(path) { +function loadAsset(path) { return new Promise((resolve) => { const img = new Image(); img.src = path; img.onload = () => { // image loaded and ready to be used + resolve(img); } - resolve(img); }) }