From 7895f3d3aea8d8fc2a98f56fb6097c6c66558b56 Mon Sep 17 00:00:00 2001 From: Ilya Kantor Date: Sat, 1 Jul 2017 10:44:36 +0300 Subject: [PATCH] minor --- 6-async/01-callbacks/article.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/6-async/01-callbacks/article.md b/6-async/01-callbacks/article.md index 23fb6b75..60ed5e83 100644 --- a/6-async/01-callbacks/article.md +++ b/6-async/01-callbacks/article.md @@ -29,7 +29,8 @@ The call initiates the script loading, then the execution continues. While the s ```js loadScript('/my/script.js'); -// the code below doesn't wait for the script loading to finish +// the code below loadScript doesn't wait for the script loading to finish +// ... ``` Now let's say we want to use the new script when it loads. It probably declares new functions, so we'd like to run them. @@ -44,7 +45,7 @@ newFunction(); // no such function! */!* ``` -Naturally, the browser probably didn't have time to load the script. As of now, `loadScript` function doesn't provide a way to track the load completion. The script loads and eventually runs, that's all. But we'd like to know when happens, to use new functions and variables from that script. +Naturally, the browser probably didn't have time to load the script. So the immediate call to the new function fails. As of now, `loadScript` function doesn't provide a way to track the load completion. The script loads and eventually runs, that's all. But we'd like to know when happens, to use new functions and variables from that script. Let's add a `callback` function as a second argument to `loadScript` that should execute when the script loads: @@ -150,7 +151,7 @@ function loadScript(src, callback) { *!* script.onload = () => callback(null, script); - script.onerror = () => callback(new Error(`Script load error ` + src)); + script.onerror = () => callback(new Error(`Script load error for ${src}`)); */!* document.head.append(script);