diff --git a/1-js/04-object-basics/04-object-methods/article.md b/1-js/04-object-basics/04-object-methods/article.md index cdb44a6b..5ef5b24e 100644 --- a/1-js/04-object-basics/04-object-methods/article.md +++ b/1-js/04-object-basics/04-object-methods/article.md @@ -214,7 +214,7 @@ sayHi(); // undefined In this case `this` is `undefined` in strict mode. If we try to access `this.name`, there will be an error. -In non-strict mode (if one forgets `use strict`) the value of `this` in such case will be the *global object* (`window` in a browser, we'll get to it later). This is a historical behavior that `"use strict"` fixes. +In non-strict mode the value of `this` in such case will be the *global object* (`window` in a browser, we'll get to it later in the chapter [](info:global-object)). This is a historical behavior that `"use strict"` fixes. Please note that usually a call of a function that uses `this` without an object is not normal, but rather a programming mistake. If a function has `this`, then it is usually meant to be called in the context of an object. diff --git a/1-js/06-advanced-functions/03-closure/article.md b/1-js/06-advanced-functions/03-closure/article.md index 2f10e7dc..21408d78 100644 --- a/1-js/06-advanced-functions/03-closure/article.md +++ b/1-js/06-advanced-functions/03-closure/article.md @@ -70,7 +70,7 @@ The Lexical Environment object consists of two parts: 1. *Environment Record* -- an object that has all local variables as its properties (and some other information like the value of `this`). 2. A reference to the *outer lexical environment*, usually the one associated with the code lexically right outside of it (outside of the current curly brackets). -So, a "variable" is just a property of the special internal object, Environment Record. "To get or change a variable" means "to get or change a property of the Lexical Environment". +**So, a "variable" is just a property of the special internal object, Environment Record. "To get or change a variable" means "to get or change a property of that object".** For instance, in this simple code, there is only one Lexical Environment: @@ -100,7 +100,11 @@ To summarize: ### Function Declaration -Function Declarations are special. Unlike `let` variables, they are processed not when the execution reaches them, but when a Lexical Environment is created. For the global Lexical Environment, it means the moment when the script is started. +Till now, we only observed variables. Now enter Function Declarations. + +**Unlike `let` variables, they are fully initialized not when the execution reaches them, but earlier, when a Lexical Environment is created.** + +For top-level functions, it means the moment when the script is started. That is why we can call a function declaration before it is defined. @@ -111,10 +115,14 @@ The code below demonstrates that the Lexical Environment is non-empty from the b ### Inner and outer Lexical Environment -During the call, `say()` uses an outer variable, so let's look at the details of what's going on. +Now let's go on and explore what happens when a function accesses an outer variable. + +During the call, `say()` uses the outer variable `phrase`, let's look at the details of what's going on. First, when a function runs, a new function Lexical Environment is created automatically. That's a general rule for all functions. That Lexical Environment is used to store local variables and parameters of the call. +For instance, for `say("John")`, it looks like this (the execution is at the line, labelled with an arrow): + -Here's the picture of Lexical Environments when the execution is inside `say("John")`, at the line labelled with an arrow: - ![lexical environment](lexical-environment-simple.png) -During the function call we have two Lexical Environments: the inner one (for the function call) and the outer one (global): +So, during the function call we have two Lexical Environments: the inner one (for the function call) and the outer one (global): -- The inner Lexical Environment corresponds to the current execution of `say`. It has a single variable: `name`, the function argument. We called `say("John")`, so the value of `name` is `"John"`. +- The inner Lexical Environment corresponds to the current execution of `say`. + + It has a single variable: `name`, the function argument. We called `say("John")`, so the value of `name` is `"John"`. - The outer Lexical Environment is the global Lexical Environment. -The inner Lexical Environment has the `outer` reference to the outer one. + It has `phrase` and the function itself. -**When code wants to access a variable -- it is first searched for in the inner Lexical Environment, then in the outer one, then the more outer one and so on until the end of the chain.** +The inner Lexical Environment has a reference to the outer one. + +**When the code wants to access a variable -- the inner Lexical Environment is searched first, then the outer one, then the more outer one and so on until the end of the chain.** If a variable is not found anywhere, that's an error in strict mode. Without `use strict`, an assignment to an undefined variable creates a new global variable, for backwards compatibility. Let's see how the search proceeds in our example: - When the `alert` inside `say` wants to access `name`, it finds it immediately in the function Lexical Environment. -- When it wants to access `phrase`, then there is no `phrase` locally, so it follows the `outer` reference and finds it globally. +- When it wants to access `phrase`, then there is no `phrase` locally, so it follows the reference to the enclosing Lexical Environment and finds it there. ![lexical environment lookup](lexical-environment-simple-lookup.png) @@ -211,11 +221,11 @@ function sayHiBye(firstName, lastName) { } ``` -Here the *nested* function `getFullName()` is made for convenience. It can access the outer variables and so can return the full name. +Here the *nested* function `getFullName()` is made for convenience. It can access the outer variables and so can return the full name. Nested functions are quite common in Javascript. -What's more interesting, a nested function can be returned: either as a property of a new object (if the outer function creates an object with methods) or as a result by itself. It can then be used somewhere else. No matter where, it still has access to the same outer variables. +What's much more interesting, a nested function can be returned: either as a property of a new object (if the outer function creates an object with methods) or as a result by itself. It can then be used somewhere else. No matter where, it still has access to the same outer variables. -An example with the constructor function (see the chapter ): +For instance, here the nested function is assigned to the new object by the [constructor function](info:constructor-new): ```js run // constructor function returns a new object @@ -228,10 +238,10 @@ function User(name) { } let user = new User("John"); -user.sayHi(); // the method code has access to the outer "name" +user.sayHi(); // the method "sayHi" code has access to the outer "name" ``` -An example with returning a function: +And here we just create and return a "counting" function: ```js run function makeCounter() { @@ -249,7 +259,7 @@ alert( counter() ); // 1 alert( counter() ); // 2 ``` -Let's go on with the `makeCounter` example. It creates the "counter" function that returns the next number on each invocation. Despite being simple, slightly modified variants of that code have practical uses, for instance, as a [pseudorandom number generator](https://en.wikipedia.org/wiki/Pseudorandom_number_generator), and more. So the example is not as artificial as it may appear. +Let's go on with the `makeCounter` example. It creates the "counter" function that returns the next number on each invocation. Despite being simple, slightly modified variants of that code have practical uses, for instance, as a [pseudorandom number generator](https://en.wikipedia.org/wiki/Pseudorandom_number_generator), and more. How does the counter work internally? @@ -303,9 +313,11 @@ Hopefully, the situation with outer variables is quite clear for you now. But in ## Environments in detail -Now that you understand how closures work generally, we can descend to the very nuts and bolts. +Now that you understand how closures work generally, that's already very good. -Here's what's going on in the `makeCounter` example step-by-step, follow it to make sure that you understand everything. Please note the additional `[[Environment]]` property that we didn't cover yet. +Here's what's going on in the `makeCounter` example step-by-step, follow it to make sure that you know things in the very detail. + +Please note the additional `[[Environment]]` property is covered here. We didn't mention it before for simplicity. 1. When the script has just started, there is only global Lexical Environment: @@ -313,7 +325,7 @@ Here's what's going on in the `makeCounter` example step-by-step, follow it to m At that starting moment there is only `makeCounter` function, because it's a Function Declaration. It did not run yet. - All functions "on birth" receive a hidden property `[[Environment]]` with a reference to the Lexical Environment of their creation. We didn't talk about it yet, but that's how the function knows where it was made. + **All functions "on birth" receive a hidden property `[[Environment]]` with a reference to the Lexical Environment of their creation.** We didn't talk about it yet, but that's how the function knows where it was made. Here, `makeCounter` is created in the global Lexical Environment, so `[[Environment]]` keeps a reference to it. @@ -389,13 +401,13 @@ When on an interview, a frontend developer gets a question about "what's a closu ## Code blocks and loops, IIFE -The examples above concentrated on functions. But Lexical Environments also exist for code blocks `{...}`. +The examples above concentrated on functions. But a Lexical Environment exists for any code block `{...}`. -They are created when a code block runs and contain block-local variables. Here are a couple of examples. +A Lexical Environment is created when a code block runs and contains block-local variables. Here are a couple of examples. -## If +### If -In the example below, when the execution goes into `if` block, the new "if-only" Lexical Environment is created for it: +In the example below, the `user` variable exists only in the `if` block: - ```js untrusted run no-strict refresh - var phrase = "Hello"; - - function sayHi() { - alert(phrase); - } - - // can read from window - alert( window.phrase ); // Hello (global var) - alert( window.sayHi ); // function (global function declaration) - - // can write to window (creates a new global variable) - window.test = 5; - - alert(test); // 5 - ``` - -...But the global object does not have variables declared with `let/const`! - -```js untrusted run no-strict refresh -*!*let*/!* user = "John"; -alert(user); // John - -alert(window.user); // undefined, don't have let -alert("user" in window); // false +// the same as +window.alert("Hello"); ``` -```smart header="The global object is not a global Environment Record" -In versions of ECMAScript prior to ES-2015, there were no `let/const` variables, only `var`. And global object was used as a global Environment Record (wordings were a bit different, but that's the gist). +We can reference other built-in functions like `Array` as `window.Array` and create our own properties on it. -But starting from ES-2015, these entities are split apart. There's a global Lexical Environment with its Environment Record. And there's a global object that provides *some* of the global variables. +## Browser: the "window" object -As a practical difference, global `let/const` variables are definitively properties of the global Environment Record, but they do not exist in the global object. +For historical reasons, in-browser `window` object is a bit messed up. -Naturally, that's because the idea of a global object as a way to access "all global things" comes from ancient times. Nowadays it's not considered to be a good thing. Modern language features like `let/const` do not make friends with it, but old ones are still compatible. -``` +1. It provides the "browser window" functionality, besides playing the role of a global object. -## Uses of "window" - -In server-side environments like Node.JS, the `global` object is used exceptionally rarely. Probably it would be fair to say "never". - -In-browser `window` is sometimes used though. - -Usually, it's not a good idea to use it, but here are some examples you can meet. - -1. To access exactly the global variable if the function has the local one with the same name. - - ```js untrusted run no-strict refresh - var user = "Global"; - - function sayHi() { - var user = "Local"; - - *!* - alert(window.user); // Global - */!* - } - - sayHi(); - ``` - - Such use is a workaround. Would be better to name variables differently, that won't require use to write the code it this way. And please note `"var"` before `user`. The trick doesn't work with `let` variables. - -2. To check if a certain global variable or a builtin exists. - - For instance, we want to check whether a global function `XMLHttpRequest` exists. - - We can't write `if (XMLHttpRequest)`, because if there's no `XMLHttpRequest`, there will be an error (variable not defined). - - But we can read it from `window.XMLHttpRequest`: + We can use `window` to access properties and methods, specific to the browser window: ```js run - if (window.XMLHttpRequest) { - alert('XMLHttpRequest exists!') - } + alert(window.innerHeight); // shows the browser window height + + window.open('http://google.com'); // opens a new browser window ``` - If there is no such global function then `window.XMLHttpRequest` is just a non-existing object property. That's `undefined`, no error, so it works. +2. Top-level `var` variables and function declarations automatically become properties of `window`. - We can also write the test without `window`: + For instance: + ```js untrusted run no-strict refresh + var x = 5; - ```js - if (typeof XMLHttpRequest == 'function') { - /* is there a function XMLHttpRequest? */ - } + alert(window.x); // 5 (var x becomes a property of window) + + window.x = 0; + + alert(x); // 0, variable modified ``` - This doesn't use `window`, but is (theoretically) less reliable, because `typeof` may use a local XMLHttpRequest, and we want the global one. + Please note, that doesn't happen with more modern `let/const` declarations: + ```js untrusted run no-strict refresh + let x = 5; -3. To take the variable from the right window. That's probably the most valid use case. + alert(window.x); // undefined ("let" doesn't create a window property) + ``` - A browser may open multiple windows and tabs. A window may also embed another one in ` + ``` - Here, first two alerts use the current window, and the latter two take variables from `iframe` window. Can be any variables if `iframe` originates from the same protocol/host/port. +4. And, a minor thing, but still: the value of `this` in the global scope is `window`. -## "this" and global object + ```js untrusted run no-strict refresh + alert(this); // window + ``` -Sometimes, the value of `this` is exactly the global object. That's rarely used, but some scripts rely on that. +Why was it made like this? At the time of the language creation, the idea to merge multiple aspects into a single `window` object was to "make things simple". But since then many things changed. Tiny scripts became big applications that require proper architecture. -1. In the browser, the value of `this` in the global area is `window`: +Is it good that different scripts (possibly from different sources) see variables of each other? + +No, it's not, because it may lead to naming conflicts: the same variable name can be used in two scripts for different purposes, so they will conflict with each other. + +As of now, the multi-purpose `window` is considered a design mistake in the language. + +Luckily, there's a "road out of hell", called "Javascript modules". + +If we set `type="module"` attribute on a ` + ``` + +- Two modules that do not see variables of each other: + + ```html run + + + + ``` + +- And, the last minor thing, the top-level value of `this` in a module is `undefined` (why should it be `window` anyway?): + + ```html run + + ``` + +**Using ` + + diff --git a/1-js/09-async/04-promise-api/one.js b/1-js/09-async/04-promise-error-handling/one.js similarity index 100% rename from 1-js/09-async/04-promise-api/one.js rename to 1-js/09-async/04-promise-error-handling/one.js diff --git a/1-js/09-async/04-promise-error-handling/three.js b/1-js/09-async/04-promise-error-handling/three.js new file mode 100644 index 00000000..8536e85a --- /dev/null +++ b/1-js/09-async/04-promise-error-handling/three.js @@ -0,0 +1,3 @@ +function three() { + alert(3); +} diff --git a/1-js/09-async/04-promise-api/two.js b/1-js/09-async/04-promise-error-handling/two.js similarity index 100% rename from 1-js/09-async/04-promise-api/two.js rename to 1-js/09-async/04-promise-error-handling/two.js diff --git a/1-js/09-async/04-promise-api/iliakan.json b/1-js/09-async/04-promise-error-handling/user.json similarity index 100% rename from 1-js/09-async/04-promise-api/iliakan.json rename to 1-js/09-async/04-promise-error-handling/user.json diff --git a/1-js/09-async/04-promise-api/01-promise-errors-as-results/solution.md b/1-js/09-async/05-promise-api/01-promise-errors-as-results/solution.md similarity index 100% rename from 1-js/09-async/04-promise-api/01-promise-errors-as-results/solution.md rename to 1-js/09-async/05-promise-api/01-promise-errors-as-results/solution.md diff --git a/1-js/09-async/04-promise-api/01-promise-errors-as-results/solution.view/index.html b/1-js/09-async/05-promise-api/01-promise-errors-as-results/solution.view/index.html similarity index 100% rename from 1-js/09-async/04-promise-api/01-promise-errors-as-results/solution.view/index.html rename to 1-js/09-async/05-promise-api/01-promise-errors-as-results/solution.view/index.html diff --git a/1-js/09-async/04-promise-api/01-promise-errors-as-results/source.view/index.html b/1-js/09-async/05-promise-api/01-promise-errors-as-results/source.view/index.html similarity index 100% rename from 1-js/09-async/04-promise-api/01-promise-errors-as-results/source.view/index.html rename to 1-js/09-async/05-promise-api/01-promise-errors-as-results/source.view/index.html diff --git a/1-js/09-async/04-promise-api/01-promise-errors-as-results/task.md b/1-js/09-async/05-promise-api/01-promise-errors-as-results/task.md similarity index 100% rename from 1-js/09-async/04-promise-api/01-promise-errors-as-results/task.md rename to 1-js/09-async/05-promise-api/01-promise-errors-as-results/task.md diff --git a/1-js/09-async/04-promise-api/02-promise-errors-as-results-2/solution.md b/1-js/09-async/05-promise-api/02-promise-errors-as-results-2/solution.md similarity index 100% rename from 1-js/09-async/04-promise-api/02-promise-errors-as-results-2/solution.md rename to 1-js/09-async/05-promise-api/02-promise-errors-as-results-2/solution.md diff --git a/1-js/09-async/04-promise-api/02-promise-errors-as-results-2/solution.view/index.html b/1-js/09-async/05-promise-api/02-promise-errors-as-results-2/solution.view/index.html similarity index 100% rename from 1-js/09-async/04-promise-api/02-promise-errors-as-results-2/solution.view/index.html rename to 1-js/09-async/05-promise-api/02-promise-errors-as-results-2/solution.view/index.html diff --git a/1-js/09-async/04-promise-api/02-promise-errors-as-results-2/source.view/index.html b/1-js/09-async/05-promise-api/02-promise-errors-as-results-2/source.view/index.html similarity index 100% rename from 1-js/09-async/04-promise-api/02-promise-errors-as-results-2/source.view/index.html rename to 1-js/09-async/05-promise-api/02-promise-errors-as-results-2/source.view/index.html diff --git a/1-js/09-async/04-promise-api/02-promise-errors-as-results-2/task.md b/1-js/09-async/05-promise-api/02-promise-errors-as-results-2/task.md similarity index 100% rename from 1-js/09-async/04-promise-api/02-promise-errors-as-results-2/task.md rename to 1-js/09-async/05-promise-api/02-promise-errors-as-results-2/task.md diff --git a/1-js/09-async/04-promise-api/article.md b/1-js/09-async/05-promise-api/article.md similarity index 100% rename from 1-js/09-async/04-promise-api/article.md rename to 1-js/09-async/05-promise-api/article.md diff --git a/1-js/09-async/04-promise-api/head.html b/1-js/09-async/05-promise-api/head.html similarity index 100% rename from 1-js/09-async/04-promise-api/head.html rename to 1-js/09-async/05-promise-api/head.html diff --git a/1-js/09-async/05-promise-api/iliakan.json b/1-js/09-async/05-promise-api/iliakan.json new file mode 100644 index 00000000..32f89971 --- /dev/null +++ b/1-js/09-async/05-promise-api/iliakan.json @@ -0,0 +1,4 @@ +{ + "name": "iliakan", + "isAdmin": true +} diff --git a/1-js/09-async/05-promise-api/one.js b/1-js/09-async/05-promise-api/one.js new file mode 100644 index 00000000..948a60e0 --- /dev/null +++ b/1-js/09-async/05-promise-api/one.js @@ -0,0 +1,3 @@ +function one() { + alert(1); +} diff --git a/1-js/09-async/05-promise-api/two.js b/1-js/09-async/05-promise-api/two.js new file mode 100644 index 00000000..b04795b8 --- /dev/null +++ b/1-js/09-async/05-promise-api/two.js @@ -0,0 +1,3 @@ +function two() { + alert(2); +} diff --git a/1-js/09-async/05-async-await/01-rewrite-async-2/solution.md b/1-js/09-async/06-async-await/01-rewrite-async-2/solution.md similarity index 100% rename from 1-js/09-async/05-async-await/01-rewrite-async-2/solution.md rename to 1-js/09-async/06-async-await/01-rewrite-async-2/solution.md diff --git a/1-js/09-async/05-async-await/01-rewrite-async-2/task.md b/1-js/09-async/06-async-await/01-rewrite-async-2/task.md similarity index 100% rename from 1-js/09-async/05-async-await/01-rewrite-async-2/task.md rename to 1-js/09-async/06-async-await/01-rewrite-async-2/task.md diff --git a/1-js/09-async/05-async-await/01-rewrite-async/solution.md b/1-js/09-async/06-async-await/01-rewrite-async/solution.md similarity index 100% rename from 1-js/09-async/05-async-await/01-rewrite-async/solution.md rename to 1-js/09-async/06-async-await/01-rewrite-async/solution.md diff --git a/1-js/09-async/05-async-await/01-rewrite-async/task.md b/1-js/09-async/06-async-await/01-rewrite-async/task.md similarity index 100% rename from 1-js/09-async/05-async-await/01-rewrite-async/task.md rename to 1-js/09-async/06-async-await/01-rewrite-async/task.md diff --git a/1-js/09-async/05-async-await/article.md b/1-js/09-async/06-async-await/article.md similarity index 100% rename from 1-js/09-async/05-async-await/article.md rename to 1-js/09-async/06-async-await/article.md diff --git a/1-js/09-async/05-async-await/head.html b/1-js/09-async/06-async-await/head.html similarity index 100% rename from 1-js/09-async/05-async-await/head.html rename to 1-js/09-async/06-async-await/head.html diff --git a/1-js/09-async/06-async-iteration/article.md b/1-js/09-async/06-async-iteration/article.md deleted file mode 100644 index c7ab8d64..00000000 --- a/1-js/09-async/06-async-iteration/article.md +++ /dev/null @@ -1,4 +0,0 @@ - -# Async iteration - -TODO diff --git a/1-js/09-async/07-async-iteration-generators/article.md b/1-js/09-async/07-async-iteration-generators/article.md new file mode 100644 index 00000000..5042aaa2 --- /dev/null +++ b/1-js/09-async/07-async-iteration-generators/article.md @@ -0,0 +1,20 @@ + +# Async iteration and generators + +In web-programming, we often need to work with fragmented data that comes piece-by-piece. + +That happens when we upload or download a file. Or we need to fetch paginated data. + + +For +Either we need to download or upload something, or we need + +In the previous chapter we saw how `async/await` allows to write asynchronous code. + +But they don't solve + + + +Regular iterators work fine with the data that doesn't take time to generate. + +A `for..of` loop assumes that we diff --git a/1-js/10-generators/01-generator/01-pseudo-random-generator/solution.md b/1-js/10-generators/01-generator/01-pseudo-random-generator/solution.md deleted file mode 100644 index 2003b0fe..00000000 --- a/1-js/10-generators/01-generator/01-pseudo-random-generator/solution.md +++ /dev/null @@ -1,19 +0,0 @@ - -Please note, the same can be done with a regular function, like this: - -```js run -function pseudoRandom(seed) { - let value = seed; - - return function() { - value = value * 16807 % 2147483647; - return value; - } -} - -let generator = pseudoRandom(1); - -alert(generator()); // 16807 -alert(generator()); // 282475249 -alert(generator()); // 1622650073 -``` diff --git a/1-js/10-generators/01-generator/anon.png b/1-js/10-generators/01-generator/anon.png deleted file mode 100644 index a1675d2f..00000000 Binary files a/1-js/10-generators/01-generator/anon.png and /dev/null differ diff --git a/1-js/10-generators/01-generator/genYield2-2.png b/1-js/10-generators/01-generator/genYield2-2.png deleted file mode 100644 index cef1d7b2..00000000 Binary files a/1-js/10-generators/01-generator/genYield2-2.png and /dev/null differ diff --git a/1-js/10-generators/01-generator/genYield2-2@2x.png b/1-js/10-generators/01-generator/genYield2-2@2x.png deleted file mode 100644 index f377c210..00000000 Binary files a/1-js/10-generators/01-generator/genYield2-2@2x.png and /dev/null differ diff --git a/1-js/10-generators/01-generator/genYield2-3.png b/1-js/10-generators/01-generator/genYield2-3.png deleted file mode 100644 index 22cc2a9d..00000000 Binary files a/1-js/10-generators/01-generator/genYield2-3.png and /dev/null differ diff --git a/1-js/10-generators/01-generator/genYield2-3@2x.png b/1-js/10-generators/01-generator/genYield2-3@2x.png deleted file mode 100644 index c288a4b7..00000000 Binary files a/1-js/10-generators/01-generator/genYield2-3@2x.png and /dev/null differ diff --git a/1-js/10-generators/01-generator/genYield2.png b/1-js/10-generators/01-generator/genYield2.png deleted file mode 100644 index 1e29a1f8..00000000 Binary files a/1-js/10-generators/01-generator/genYield2.png and /dev/null differ diff --git a/1-js/10-generators/01-generator/genYield2@2x.png b/1-js/10-generators/01-generator/genYield2@2x.png deleted file mode 100644 index 1cf8b1fa..00000000 Binary files a/1-js/10-generators/01-generator/genYield2@2x.png and /dev/null differ diff --git a/1-js/10-generators/01-generator/generateSequence-1.png b/1-js/10-generators/01-generator/generateSequence-1.png deleted file mode 100644 index 76e84112..00000000 Binary files a/1-js/10-generators/01-generator/generateSequence-1.png and /dev/null differ diff --git a/1-js/10-generators/01-generator/generateSequence-1@2x.png b/1-js/10-generators/01-generator/generateSequence-1@2x.png deleted file mode 100644 index cd2a416d..00000000 Binary files a/1-js/10-generators/01-generator/generateSequence-1@2x.png and /dev/null differ diff --git a/1-js/10-generators/01-generator/generateSequence-2.png b/1-js/10-generators/01-generator/generateSequence-2.png deleted file mode 100644 index 8c7db83f..00000000 Binary files a/1-js/10-generators/01-generator/generateSequence-2.png and /dev/null differ diff --git a/1-js/10-generators/01-generator/generateSequence-2@2x.png b/1-js/10-generators/01-generator/generateSequence-2@2x.png deleted file mode 100644 index e270fdcb..00000000 Binary files a/1-js/10-generators/01-generator/generateSequence-2@2x.png and /dev/null differ diff --git a/1-js/10-generators/01-generator/generateSequence-3.png b/1-js/10-generators/01-generator/generateSequence-3.png deleted file mode 100644 index 678d3b5e..00000000 Binary files a/1-js/10-generators/01-generator/generateSequence-3.png and /dev/null differ diff --git a/1-js/10-generators/01-generator/generateSequence-3@2x.png b/1-js/10-generators/01-generator/generateSequence-3@2x.png deleted file mode 100644 index 99b23031..00000000 Binary files a/1-js/10-generators/01-generator/generateSequence-3@2x.png and /dev/null differ diff --git a/1-js/10-generators/01-generator/generateSequence-4.png b/1-js/10-generators/01-generator/generateSequence-4.png deleted file mode 100644 index ce3cc2a2..00000000 Binary files a/1-js/10-generators/01-generator/generateSequence-4.png and /dev/null differ diff --git a/1-js/10-generators/01-generator/generateSequence-4@2x.png b/1-js/10-generators/01-generator/generateSequence-4@2x.png deleted file mode 100644 index 81c234a6..00000000 Binary files a/1-js/10-generators/01-generator/generateSequence-4@2x.png and /dev/null differ diff --git a/1-js/10-generators/02-async-iteration/article.md b/1-js/10-generators/02-async-iteration/article.md deleted file mode 100644 index fd03e547..00000000 --- a/1-js/10-generators/02-async-iteration/article.md +++ /dev/null @@ -1,9 +0,0 @@ - -# Async iteration - - -... - -Async generators may initially look complex, but in fact they are not. - -The resulting syntax is simple and easy to use. diff --git a/1-js/10-generators/index.md b/1-js/10-generators/index.md deleted file mode 100644 index 89dc6f34..00000000 --- a/1-js/10-generators/index.md +++ /dev/null @@ -1,2 +0,0 @@ - -# Generators diff --git a/1-js/11-modules/01-modules-intro/article.md b/1-js/10-modules/01-modules-intro/article.md similarity index 92% rename from 1-js/11-modules/01-modules-intro/article.md rename to 1-js/10-modules/01-modules-intro/article.md index c67c0c1d..bee476eb 100644 --- a/1-js/11-modules/01-modules-intro/article.md +++ b/1-js/10-modules/01-modules-intro/article.md @@ -87,14 +87,14 @@ Module scripts, have several important differences, that's why `type="module"` i ```html run @@ -102,7 +102,11 @@ Module scripts, have several important differences, that's why `type="module"` i ``` - So, when we're using modules, we should be aware that HTML-document can show up before the Javascript application is ready. Certain functionality may not work yet. We should put transparent overlays or "loading indicators", or otherwise ensure that the visitor won't be confused because of it. + Please note: the second script actually works before the first! So we'll see `undefined` first, and then `object`. + + That's because modules are deferred, so way wait for the document to be processed. The regular scripts runs immediately, so we saw its output first. + + When using modules, we should be aware that HTML-document can show up before the Javascript application is ready. Some functionality may not work yet. We should put transparent overlays or "loading indicators", or otherwise ensure that the visitor won't be confused because of it. 4. Async attribute ` + + +``` + ## Summary To summarize, the core concepts are: diff --git a/1-js/11-modules/01-modules-intro/say.view/index.html b/1-js/10-modules/01-modules-intro/say.view/index.html similarity index 100% rename from 1-js/11-modules/01-modules-intro/say.view/index.html rename to 1-js/10-modules/01-modules-intro/say.view/index.html diff --git a/1-js/11-modules/01-modules-intro/say.view/say.js b/1-js/10-modules/01-modules-intro/say.view/say.js similarity index 100% rename from 1-js/11-modules/01-modules-intro/say.view/say.js rename to 1-js/10-modules/01-modules-intro/say.view/say.js diff --git a/1-js/11-modules/02-import-export/article.md b/1-js/10-modules/02-import-export/article.md similarity index 100% rename from 1-js/11-modules/02-import-export/article.md rename to 1-js/10-modules/02-import-export/article.md diff --git a/1-js/11-modules/03-modules-dynamic-imports/article.md b/1-js/10-modules/03-modules-dynamic-imports/article.md similarity index 100% rename from 1-js/11-modules/03-modules-dynamic-imports/article.md rename to 1-js/10-modules/03-modules-dynamic-imports/article.md diff --git a/1-js/11-modules/03-modules-dynamic-imports/say.view/index.html b/1-js/10-modules/03-modules-dynamic-imports/say.view/index.html similarity index 100% rename from 1-js/11-modules/03-modules-dynamic-imports/say.view/index.html rename to 1-js/10-modules/03-modules-dynamic-imports/say.view/index.html diff --git a/1-js/11-modules/03-modules-dynamic-imports/say.view/say.js b/1-js/10-modules/03-modules-dynamic-imports/say.view/say.js similarity index 100% rename from 1-js/11-modules/03-modules-dynamic-imports/say.view/say.js rename to 1-js/10-modules/03-modules-dynamic-imports/say.view/say.js diff --git a/1-js/11-modules/index.md b/1-js/10-modules/index.md similarity index 100% rename from 1-js/11-modules/index.md rename to 1-js/10-modules/index.md diff --git a/figures.sketch b/figures.sketch index e3c50f37..905d67e7 100644 Binary files a/figures.sketch and b/figures.sketch differ