diff --git a/1-js/1-getting-started/1-intro/article.md b/1-js/01-getting-started/1-intro/article.md similarity index 100% rename from 1-js/1-getting-started/1-intro/article.md rename to 1-js/01-getting-started/1-intro/article.md diff --git a/1-js/1-getting-started/1-intro/limitations.png b/1-js/01-getting-started/1-intro/limitations.png similarity index 100% rename from 1-js/1-getting-started/1-intro/limitations.png rename to 1-js/01-getting-started/1-intro/limitations.png diff --git a/1-js/1-getting-started/1-intro/limitations@2x.png b/1-js/01-getting-started/1-intro/limitations@2x.png similarity index 100% rename from 1-js/1-getting-started/1-intro/limitations@2x.png rename to 1-js/01-getting-started/1-intro/limitations@2x.png diff --git a/1-js/1-getting-started/2-editor/article.md b/1-js/01-getting-started/2-editor/article.md similarity index 100% rename from 1-js/1-getting-started/2-editor/article.md rename to 1-js/01-getting-started/2-editor/article.md diff --git a/1-js/1-getting-started/3-devtools/article.md b/1-js/01-getting-started/3-devtools/article.md similarity index 100% rename from 1-js/1-getting-started/3-devtools/article.md rename to 1-js/01-getting-started/3-devtools/article.md diff --git a/1-js/1-getting-started/3-devtools/bug.html b/1-js/01-getting-started/3-devtools/bug.html similarity index 100% rename from 1-js/1-getting-started/3-devtools/bug.html rename to 1-js/01-getting-started/3-devtools/bug.html diff --git a/1-js/1-getting-started/3-devtools/chrome.png b/1-js/01-getting-started/3-devtools/chrome.png similarity index 100% rename from 1-js/1-getting-started/3-devtools/chrome.png rename to 1-js/01-getting-started/3-devtools/chrome.png diff --git a/1-js/1-getting-started/3-devtools/chrome@2x.png b/1-js/01-getting-started/3-devtools/chrome@2x.png similarity index 100% rename from 1-js/1-getting-started/3-devtools/chrome@2x.png rename to 1-js/01-getting-started/3-devtools/chrome@2x.png diff --git a/1-js/1-getting-started/3-devtools/safari.png b/1-js/01-getting-started/3-devtools/safari.png similarity index 100% rename from 1-js/1-getting-started/3-devtools/safari.png rename to 1-js/01-getting-started/3-devtools/safari.png diff --git a/1-js/1-getting-started/3-devtools/safari@2x.png b/1-js/01-getting-started/3-devtools/safari@2x.png similarity index 100% rename from 1-js/1-getting-started/3-devtools/safari@2x.png rename to 1-js/01-getting-started/3-devtools/safari@2x.png diff --git a/1-js/1-getting-started/index.md b/1-js/01-getting-started/index.md similarity index 100% rename from 1-js/1-getting-started/index.md rename to 1-js/01-getting-started/index.md diff --git a/1-js/2-first-steps/01-hello-world/1-hello-alert/solution.md b/1-js/02-first-steps/01-hello-world/1-hello-alert/solution.md similarity index 100% rename from 1-js/2-first-steps/01-hello-world/1-hello-alert/solution.md rename to 1-js/02-first-steps/01-hello-world/1-hello-alert/solution.md diff --git a/1-js/2-first-steps/01-hello-world/1-hello-alert/solution.view/index.html b/1-js/02-first-steps/01-hello-world/1-hello-alert/solution.view/index.html similarity index 100% rename from 1-js/2-first-steps/01-hello-world/1-hello-alert/solution.view/index.html rename to 1-js/02-first-steps/01-hello-world/1-hello-alert/solution.view/index.html diff --git a/1-js/2-first-steps/01-hello-world/1-hello-alert/task.md b/1-js/02-first-steps/01-hello-world/1-hello-alert/task.md similarity index 100% rename from 1-js/2-first-steps/01-hello-world/1-hello-alert/task.md rename to 1-js/02-first-steps/01-hello-world/1-hello-alert/task.md diff --git a/1-js/2-first-steps/01-hello-world/2-hello-alert-ext/alert.js b/1-js/02-first-steps/01-hello-world/2-hello-alert-ext/alert.js similarity index 100% rename from 1-js/2-first-steps/01-hello-world/2-hello-alert-ext/alert.js rename to 1-js/02-first-steps/01-hello-world/2-hello-alert-ext/alert.js diff --git a/1-js/2-first-steps/01-hello-world/2-hello-alert-ext/index.html b/1-js/02-first-steps/01-hello-world/2-hello-alert-ext/index.html similarity index 100% rename from 1-js/2-first-steps/01-hello-world/2-hello-alert-ext/index.html rename to 1-js/02-first-steps/01-hello-world/2-hello-alert-ext/index.html diff --git a/1-js/2-first-steps/01-hello-world/2-hello-alert-ext/solution.md b/1-js/02-first-steps/01-hello-world/2-hello-alert-ext/solution.md similarity index 100% rename from 1-js/2-first-steps/01-hello-world/2-hello-alert-ext/solution.md rename to 1-js/02-first-steps/01-hello-world/2-hello-alert-ext/solution.md diff --git a/1-js/2-first-steps/01-hello-world/2-hello-alert-ext/task.md b/1-js/02-first-steps/01-hello-world/2-hello-alert-ext/task.md similarity index 100% rename from 1-js/2-first-steps/01-hello-world/2-hello-alert-ext/task.md rename to 1-js/02-first-steps/01-hello-world/2-hello-alert-ext/task.md diff --git a/1-js/2-first-steps/01-hello-world/article.md b/1-js/02-first-steps/01-hello-world/article.md similarity index 100% rename from 1-js/2-first-steps/01-hello-world/article.md rename to 1-js/02-first-steps/01-hello-world/article.md diff --git a/1-js/2-first-steps/01-hello-world/hello-world-render.png b/1-js/02-first-steps/01-hello-world/hello-world-render.png similarity index 100% rename from 1-js/2-first-steps/01-hello-world/hello-world-render.png rename to 1-js/02-first-steps/01-hello-world/hello-world-render.png diff --git a/1-js/2-first-steps/01-hello-world/hello-world-render@2x.png b/1-js/02-first-steps/01-hello-world/hello-world-render@2x.png similarity index 100% rename from 1-js/2-first-steps/01-hello-world/hello-world-render@2x.png rename to 1-js/02-first-steps/01-hello-world/hello-world-render@2x.png diff --git a/1-js/2-first-steps/02-structure/article.md b/1-js/02-first-steps/02-structure/article.md similarity index 97% rename from 1-js/2-first-steps/02-structure/article.md rename to 1-js/02-first-steps/02-structure/article.md index 7e6faa42..0066b33a 100644 --- a/1-js/2-first-steps/02-structure/article.md +++ b/1-js/02-first-steps/02-structure/article.md @@ -157,6 +157,4 @@ Please, don't hesitate to comment your code. Comments increase the overall code footprint, but that's not a problem at all. There are many tools which minify the code before publishing to production server. They remove comments, so they do not appear in the working scripts. So, the comments do not have any negative effects on production at all. -Further in the tutorial we'll devote a special chapter to code style, also explaining how to write better comments. - -[todo is there such a chapter?] +Further in the tutorial there will be a chapter that also explains how to write better comments. diff --git a/1-js/2-first-steps/03-strict-mode/article.md b/1-js/02-first-steps/03-strict-mode/article.md similarity index 100% rename from 1-js/2-first-steps/03-strict-mode/article.md rename to 1-js/02-first-steps/03-strict-mode/article.md diff --git a/1-js/2-first-steps/04-variables/1-hello-variables/solution.md b/1-js/02-first-steps/04-variables/1-hello-variables/solution.md similarity index 100% rename from 1-js/2-first-steps/04-variables/1-hello-variables/solution.md rename to 1-js/02-first-steps/04-variables/1-hello-variables/solution.md diff --git a/1-js/2-first-steps/04-variables/1-hello-variables/task.md b/1-js/02-first-steps/04-variables/1-hello-variables/task.md similarity index 100% rename from 1-js/2-first-steps/04-variables/1-hello-variables/task.md rename to 1-js/02-first-steps/04-variables/1-hello-variables/task.md diff --git a/1-js/2-first-steps/04-variables/2-declare-variables/solution.md b/1-js/02-first-steps/04-variables/2-declare-variables/solution.md similarity index 100% rename from 1-js/2-first-steps/04-variables/2-declare-variables/solution.md rename to 1-js/02-first-steps/04-variables/2-declare-variables/solution.md diff --git a/1-js/2-first-steps/04-variables/2-declare-variables/task.md b/1-js/02-first-steps/04-variables/2-declare-variables/task.md similarity index 100% rename from 1-js/2-first-steps/04-variables/2-declare-variables/task.md rename to 1-js/02-first-steps/04-variables/2-declare-variables/task.md diff --git a/1-js/2-first-steps/04-variables/3-uppercast-constant/solution.md b/1-js/02-first-steps/04-variables/3-uppercast-constant/solution.md similarity index 100% rename from 1-js/2-first-steps/04-variables/3-uppercast-constant/solution.md rename to 1-js/02-first-steps/04-variables/3-uppercast-constant/solution.md diff --git a/1-js/2-first-steps/04-variables/3-uppercast-constant/task.md b/1-js/02-first-steps/04-variables/3-uppercast-constant/task.md similarity index 100% rename from 1-js/2-first-steps/04-variables/3-uppercast-constant/task.md rename to 1-js/02-first-steps/04-variables/3-uppercast-constant/task.md diff --git a/1-js/2-first-steps/04-variables/article.md b/1-js/02-first-steps/04-variables/article.md similarity index 100% rename from 1-js/2-first-steps/04-variables/article.md rename to 1-js/02-first-steps/04-variables/article.md diff --git a/1-js/2-first-steps/04-variables/variable-change.png b/1-js/02-first-steps/04-variables/variable-change.png similarity index 100% rename from 1-js/2-first-steps/04-variables/variable-change.png rename to 1-js/02-first-steps/04-variables/variable-change.png diff --git a/1-js/2-first-steps/04-variables/variable-change@2x.png b/1-js/02-first-steps/04-variables/variable-change@2x.png similarity index 100% rename from 1-js/2-first-steps/04-variables/variable-change@2x.png rename to 1-js/02-first-steps/04-variables/variable-change@2x.png diff --git a/1-js/2-first-steps/04-variables/variable.png b/1-js/02-first-steps/04-variables/variable.png similarity index 100% rename from 1-js/2-first-steps/04-variables/variable.png rename to 1-js/02-first-steps/04-variables/variable.png diff --git a/1-js/2-first-steps/04-variables/variable@2x.png b/1-js/02-first-steps/04-variables/variable@2x.png similarity index 100% rename from 1-js/2-first-steps/04-variables/variable@2x.png rename to 1-js/02-first-steps/04-variables/variable@2x.png diff --git a/1-js/2-first-steps/05-types/1-string-quotes/solution.md b/1-js/02-first-steps/05-types/1-string-quotes/solution.md similarity index 100% rename from 1-js/2-first-steps/05-types/1-string-quotes/solution.md rename to 1-js/02-first-steps/05-types/1-string-quotes/solution.md diff --git a/1-js/2-first-steps/05-types/1-string-quotes/task.md b/1-js/02-first-steps/05-types/1-string-quotes/task.md similarity index 100% rename from 1-js/2-first-steps/05-types/1-string-quotes/task.md rename to 1-js/02-first-steps/05-types/1-string-quotes/task.md diff --git a/1-js/2-first-steps/05-types/article.md b/1-js/02-first-steps/05-types/article.md similarity index 99% rename from 1-js/2-first-steps/05-types/article.md rename to 1-js/02-first-steps/05-types/article.md index ce9edc09..747a17af 100644 --- a/1-js/2-first-steps/05-types/article.md +++ b/1-js/02-first-steps/05-types/article.md @@ -175,10 +175,7 @@ All other types are called "primitive", because their values can contain only a The `symbol` type is used to create unique identifiers for objects. We have to mention it here for completeness, but we'd better study them after covering objects. -[todo when ? chapter?] - ## The typeof operator [#type-typeof] -[todo we need typeof in types] The `typeof` operator returns the type of the argument. It's useful when we want to process values of different types differently, or just want to make a quick check. diff --git a/1-js/2-first-steps/06-type-conversions/1-primitive-conversions-questions/solution.md b/1-js/02-first-steps/06-type-conversions/1-primitive-conversions-questions/solution.md similarity index 100% rename from 1-js/2-first-steps/06-type-conversions/1-primitive-conversions-questions/solution.md rename to 1-js/02-first-steps/06-type-conversions/1-primitive-conversions-questions/solution.md diff --git a/1-js/2-first-steps/06-type-conversions/1-primitive-conversions-questions/task.md b/1-js/02-first-steps/06-type-conversions/1-primitive-conversions-questions/task.md similarity index 100% rename from 1-js/2-first-steps/06-type-conversions/1-primitive-conversions-questions/task.md rename to 1-js/02-first-steps/06-type-conversions/1-primitive-conversions-questions/task.md diff --git a/1-js/2-first-steps/06-type-conversions/article.md b/1-js/02-first-steps/06-type-conversions/article.md similarity index 79% rename from 1-js/2-first-steps/06-type-conversions/article.md rename to 1-js/02-first-steps/06-type-conversions/article.md index a0d923d9..8165a551 100644 --- a/1-js/2-first-steps/06-type-conversions/article.md +++ b/1-js/02-first-steps/06-type-conversions/article.md @@ -9,11 +9,9 @@ There are also cases when we need to explicitly convert a value to put things ri [cut] ```smart header="Not covering objects yet" -In this chapter we don't cover objects yet. Here we study primitives first, and then we'll add objects in the chapter [todo]. +In this chapter we don't cover objects yet. Here we study primitives first, and then we'll see what happens with objects in the chapter . ``` -[todo where we cover them? link?] - ## ToString The string conversion happens when we need a string form of a value. @@ -141,30 +139,27 @@ alert( Boolean(" ") ); // also true (any non-empty string is true) There exist three most widely used type conversions: to string, to number and to boolean. -`ToString` -: Happens when we output something, can be performed with `String(value)`. The conversion to string is usually obvious for primitive values. +**`ToString`** -- occurs when we output something, can be performed with `String(value)`. The conversion to string is usually obvious for primitive values. -`ToNumber` -: Happens in math operations, can be performed with `Number(value)`. +**`ToNumber`** -- occurs in math operations, can be performed with `Number(value)`. - The conversion follows the rules: +The conversion follows the rules: - | Value | Becomes... | - |-------|-------------| - |`undefined`|`NaN`| - |`null`|`0`| - |true / false | `1 / 0` | - | `string` | The string is read "as is", whitespaces from both sides are ignored. An empty string is `0`. An error gives `NaN`. | +| Value | Becomes... | +|-------|-------------| +|`undefined`|`NaN`| +|`null`|`0`| +|true / false | `1 / 0` | +| `string` | The string is read "as is", whitespaces from both sides are ignored. An empty string becomes `0`. An error gives `NaN`. | -ToBoolean -: Happens in logical operations, or can be performed with `Boolean(value)`. +**`ToBoolean`** -- occurs in logical operations, or can be performed with `Boolean(value)`. - Follows the rules: +Follows the rules: - | Value | Becomes... | - |-------|-------------| - |`0`, `null`, `undefined`, `NaN`, `""` |`false`| - |any other value| `true` | +| Value | Becomes... | +|-------|-------------| +|`0`, `null`, `undefined`, `NaN`, `""` |`false`| +|any other value| `true` | Most of these rules are easy to understand and memorize. The notable exceptions where people usually make mistakes are: @@ -172,6 +167,4 @@ Most of these rules are easy to understand and memorize. The notable exceptions - `undefined` is `NaN` as a number. - `"0"` is true as a boolean. -Objects are not covered here, we'll return to them in the special chapter, devoted exclusively to objects. - -[todo link?] +Objects are not covered here, we'll return to them later in the chapter , devoted exclusively to objects, after we learn more basic things about Javascript. diff --git a/1-js/2-first-steps/07-operators/1-increment-order/solution.md b/1-js/02-first-steps/07-operators/1-increment-order/solution.md similarity index 100% rename from 1-js/2-first-steps/07-operators/1-increment-order/solution.md rename to 1-js/02-first-steps/07-operators/1-increment-order/solution.md diff --git a/1-js/2-first-steps/07-operators/1-increment-order/task.md b/1-js/02-first-steps/07-operators/1-increment-order/task.md similarity index 100% rename from 1-js/2-first-steps/07-operators/1-increment-order/task.md rename to 1-js/02-first-steps/07-operators/1-increment-order/task.md diff --git a/1-js/2-first-steps/07-operators/2-assignment-result/solution.md b/1-js/02-first-steps/07-operators/2-assignment-result/solution.md similarity index 100% rename from 1-js/2-first-steps/07-operators/2-assignment-result/solution.md rename to 1-js/02-first-steps/07-operators/2-assignment-result/solution.md diff --git a/1-js/2-first-steps/07-operators/2-assignment-result/task.md b/1-js/02-first-steps/07-operators/2-assignment-result/task.md similarity index 100% rename from 1-js/2-first-steps/07-operators/2-assignment-result/task.md rename to 1-js/02-first-steps/07-operators/2-assignment-result/task.md diff --git a/1-js/2-first-steps/07-operators/article.md b/1-js/02-first-steps/07-operators/article.md similarity index 100% rename from 1-js/2-first-steps/07-operators/article.md rename to 1-js/02-first-steps/07-operators/article.md diff --git a/1-js/2-first-steps/08-comparison/1-comparison-questions/solution.md b/1-js/02-first-steps/08-comparison/1-comparison-questions/solution.md similarity index 100% rename from 1-js/2-first-steps/08-comparison/1-comparison-questions/solution.md rename to 1-js/02-first-steps/08-comparison/1-comparison-questions/solution.md diff --git a/1-js/2-first-steps/08-comparison/1-comparison-questions/task.md b/1-js/02-first-steps/08-comparison/1-comparison-questions/task.md similarity index 100% rename from 1-js/2-first-steps/08-comparison/1-comparison-questions/task.md rename to 1-js/02-first-steps/08-comparison/1-comparison-questions/task.md diff --git a/1-js/2-first-steps/08-comparison/article.md b/1-js/02-first-steps/08-comparison/article.md similarity index 100% rename from 1-js/2-first-steps/08-comparison/article.md rename to 1-js/02-first-steps/08-comparison/article.md diff --git a/1-js/2-first-steps/09-uibasic/1-simple-page/solution.md b/1-js/02-first-steps/09-uibasic/1-simple-page/solution.md similarity index 100% rename from 1-js/2-first-steps/09-uibasic/1-simple-page/solution.md rename to 1-js/02-first-steps/09-uibasic/1-simple-page/solution.md diff --git a/1-js/2-first-steps/09-uibasic/1-simple-page/task.md b/1-js/02-first-steps/09-uibasic/1-simple-page/task.md similarity index 100% rename from 1-js/2-first-steps/09-uibasic/1-simple-page/task.md rename to 1-js/02-first-steps/09-uibasic/1-simple-page/task.md diff --git a/1-js/2-first-steps/09-uibasic/article.md b/1-js/02-first-steps/09-uibasic/article.md similarity index 100% rename from 1-js/2-first-steps/09-uibasic/article.md rename to 1-js/02-first-steps/09-uibasic/article.md diff --git a/1-js/2-first-steps/10-ifelse/1-if-zero-string/solution.md b/1-js/02-first-steps/10-ifelse/1-if-zero-string/solution.md similarity index 100% rename from 1-js/2-first-steps/10-ifelse/1-if-zero-string/solution.md rename to 1-js/02-first-steps/10-ifelse/1-if-zero-string/solution.md diff --git a/1-js/2-first-steps/10-ifelse/1-if-zero-string/task.md b/1-js/02-first-steps/10-ifelse/1-if-zero-string/task.md similarity index 100% rename from 1-js/2-first-steps/10-ifelse/1-if-zero-string/task.md rename to 1-js/02-first-steps/10-ifelse/1-if-zero-string/task.md diff --git a/1-js/2-first-steps/10-ifelse/2-check-standard/ifelse_task2.png b/1-js/02-first-steps/10-ifelse/2-check-standard/ifelse_task2.png similarity index 100% rename from 1-js/2-first-steps/10-ifelse/2-check-standard/ifelse_task2.png rename to 1-js/02-first-steps/10-ifelse/2-check-standard/ifelse_task2.png diff --git a/1-js/2-first-steps/10-ifelse/2-check-standard/ifelse_task2/index.html b/1-js/02-first-steps/10-ifelse/2-check-standard/ifelse_task2/index.html similarity index 100% rename from 1-js/2-first-steps/10-ifelse/2-check-standard/ifelse_task2/index.html rename to 1-js/02-first-steps/10-ifelse/2-check-standard/ifelse_task2/index.html diff --git a/1-js/2-first-steps/10-ifelse/2-check-standard/ifelse_task2@2x.png b/1-js/02-first-steps/10-ifelse/2-check-standard/ifelse_task2@2x.png similarity index 100% rename from 1-js/2-first-steps/10-ifelse/2-check-standard/ifelse_task2@2x.png rename to 1-js/02-first-steps/10-ifelse/2-check-standard/ifelse_task2@2x.png diff --git a/1-js/2-first-steps/10-ifelse/2-check-standard/solution.md b/1-js/02-first-steps/10-ifelse/2-check-standard/solution.md similarity index 100% rename from 1-js/2-first-steps/10-ifelse/2-check-standard/solution.md rename to 1-js/02-first-steps/10-ifelse/2-check-standard/solution.md diff --git a/1-js/2-first-steps/10-ifelse/2-check-standard/task.md b/1-js/02-first-steps/10-ifelse/2-check-standard/task.md similarity index 100% rename from 1-js/2-first-steps/10-ifelse/2-check-standard/task.md rename to 1-js/02-first-steps/10-ifelse/2-check-standard/task.md diff --git a/1-js/2-first-steps/10-ifelse/3-sign/if_sign/index.html b/1-js/02-first-steps/10-ifelse/3-sign/if_sign/index.html similarity index 100% rename from 1-js/2-first-steps/10-ifelse/3-sign/if_sign/index.html rename to 1-js/02-first-steps/10-ifelse/3-sign/if_sign/index.html diff --git a/1-js/2-first-steps/10-ifelse/3-sign/solution.md b/1-js/02-first-steps/10-ifelse/3-sign/solution.md similarity index 100% rename from 1-js/2-first-steps/10-ifelse/3-sign/solution.md rename to 1-js/02-first-steps/10-ifelse/3-sign/solution.md diff --git a/1-js/2-first-steps/10-ifelse/3-sign/task.md b/1-js/02-first-steps/10-ifelse/3-sign/task.md similarity index 100% rename from 1-js/2-first-steps/10-ifelse/3-sign/task.md rename to 1-js/02-first-steps/10-ifelse/3-sign/task.md diff --git a/1-js/2-first-steps/10-ifelse/4-check-login/ifelse_task.png b/1-js/02-first-steps/10-ifelse/4-check-login/ifelse_task.png similarity index 100% rename from 1-js/2-first-steps/10-ifelse/4-check-login/ifelse_task.png rename to 1-js/02-first-steps/10-ifelse/4-check-login/ifelse_task.png diff --git a/1-js/2-first-steps/10-ifelse/4-check-login/ifelse_task@2x.png b/1-js/02-first-steps/10-ifelse/4-check-login/ifelse_task@2x.png similarity index 100% rename from 1-js/2-first-steps/10-ifelse/4-check-login/ifelse_task@2x.png rename to 1-js/02-first-steps/10-ifelse/4-check-login/ifelse_task@2x.png diff --git a/1-js/2-first-steps/10-ifelse/4-check-login/solution.md b/1-js/02-first-steps/10-ifelse/4-check-login/solution.md similarity index 100% rename from 1-js/2-first-steps/10-ifelse/4-check-login/solution.md rename to 1-js/02-first-steps/10-ifelse/4-check-login/solution.md diff --git a/1-js/2-first-steps/10-ifelse/4-check-login/task.md b/1-js/02-first-steps/10-ifelse/4-check-login/task.md similarity index 100% rename from 1-js/2-first-steps/10-ifelse/4-check-login/task.md rename to 1-js/02-first-steps/10-ifelse/4-check-login/task.md diff --git a/1-js/2-first-steps/10-ifelse/5-rewrite-if-question/solution.md b/1-js/02-first-steps/10-ifelse/5-rewrite-if-question/solution.md similarity index 100% rename from 1-js/2-first-steps/10-ifelse/5-rewrite-if-question/solution.md rename to 1-js/02-first-steps/10-ifelse/5-rewrite-if-question/solution.md diff --git a/1-js/2-first-steps/10-ifelse/5-rewrite-if-question/task.md b/1-js/02-first-steps/10-ifelse/5-rewrite-if-question/task.md similarity index 100% rename from 1-js/2-first-steps/10-ifelse/5-rewrite-if-question/task.md rename to 1-js/02-first-steps/10-ifelse/5-rewrite-if-question/task.md diff --git a/1-js/2-first-steps/10-ifelse/6-rewrite-if-else-question/solution.md b/1-js/02-first-steps/10-ifelse/6-rewrite-if-else-question/solution.md similarity index 100% rename from 1-js/2-first-steps/10-ifelse/6-rewrite-if-else-question/solution.md rename to 1-js/02-first-steps/10-ifelse/6-rewrite-if-else-question/solution.md diff --git a/1-js/2-first-steps/10-ifelse/6-rewrite-if-else-question/task.md b/1-js/02-first-steps/10-ifelse/6-rewrite-if-else-question/task.md similarity index 100% rename from 1-js/2-first-steps/10-ifelse/6-rewrite-if-else-question/task.md rename to 1-js/02-first-steps/10-ifelse/6-rewrite-if-else-question/task.md diff --git a/1-js/2-first-steps/10-ifelse/article.md b/1-js/02-first-steps/10-ifelse/article.md similarity index 100% rename from 1-js/2-first-steps/10-ifelse/article.md rename to 1-js/02-first-steps/10-ifelse/article.md diff --git a/1-js/2-first-steps/11-logical-ops/1-alert-null-2-undefined/solution.md b/1-js/02-first-steps/11-logical-ops/1-alert-null-2-undefined/solution.md similarity index 100% rename from 1-js/2-first-steps/11-logical-ops/1-alert-null-2-undefined/solution.md rename to 1-js/02-first-steps/11-logical-ops/1-alert-null-2-undefined/solution.md diff --git a/1-js/2-first-steps/11-logical-ops/1-alert-null-2-undefined/task.md b/1-js/02-first-steps/11-logical-ops/1-alert-null-2-undefined/task.md similarity index 100% rename from 1-js/2-first-steps/11-logical-ops/1-alert-null-2-undefined/task.md rename to 1-js/02-first-steps/11-logical-ops/1-alert-null-2-undefined/task.md diff --git a/1-js/2-first-steps/11-logical-ops/2-alert-or/solution.md b/1-js/02-first-steps/11-logical-ops/2-alert-or/solution.md similarity index 100% rename from 1-js/2-first-steps/11-logical-ops/2-alert-or/solution.md rename to 1-js/02-first-steps/11-logical-ops/2-alert-or/solution.md diff --git a/1-js/2-first-steps/11-logical-ops/2-alert-or/task.md b/1-js/02-first-steps/11-logical-ops/2-alert-or/task.md similarity index 100% rename from 1-js/2-first-steps/11-logical-ops/2-alert-or/task.md rename to 1-js/02-first-steps/11-logical-ops/2-alert-or/task.md diff --git a/1-js/2-first-steps/11-logical-ops/3-alert-1-null-2/solution.md b/1-js/02-first-steps/11-logical-ops/3-alert-1-null-2/solution.md similarity index 100% rename from 1-js/2-first-steps/11-logical-ops/3-alert-1-null-2/solution.md rename to 1-js/02-first-steps/11-logical-ops/3-alert-1-null-2/solution.md diff --git a/1-js/2-first-steps/11-logical-ops/3-alert-1-null-2/task.md b/1-js/02-first-steps/11-logical-ops/3-alert-1-null-2/task.md similarity index 100% rename from 1-js/2-first-steps/11-logical-ops/3-alert-1-null-2/task.md rename to 1-js/02-first-steps/11-logical-ops/3-alert-1-null-2/task.md diff --git a/1-js/2-first-steps/11-logical-ops/4-alert-and/solution.md b/1-js/02-first-steps/11-logical-ops/4-alert-and/solution.md similarity index 100% rename from 1-js/2-first-steps/11-logical-ops/4-alert-and/solution.md rename to 1-js/02-first-steps/11-logical-ops/4-alert-and/solution.md diff --git a/1-js/2-first-steps/11-logical-ops/4-alert-and/task.md b/1-js/02-first-steps/11-logical-ops/4-alert-and/task.md similarity index 100% rename from 1-js/2-first-steps/11-logical-ops/4-alert-and/task.md rename to 1-js/02-first-steps/11-logical-ops/4-alert-and/task.md diff --git a/1-js/2-first-steps/11-logical-ops/5-alert-and-or/solution.md b/1-js/02-first-steps/11-logical-ops/5-alert-and-or/solution.md similarity index 100% rename from 1-js/2-first-steps/11-logical-ops/5-alert-and-or/solution.md rename to 1-js/02-first-steps/11-logical-ops/5-alert-and-or/solution.md diff --git a/1-js/2-first-steps/11-logical-ops/5-alert-and-or/task.md b/1-js/02-first-steps/11-logical-ops/5-alert-and-or/task.md similarity index 100% rename from 1-js/2-first-steps/11-logical-ops/5-alert-and-or/task.md rename to 1-js/02-first-steps/11-logical-ops/5-alert-and-or/task.md diff --git a/1-js/2-first-steps/11-logical-ops/6-check-if-in-range/solution.md b/1-js/02-first-steps/11-logical-ops/6-check-if-in-range/solution.md similarity index 100% rename from 1-js/2-first-steps/11-logical-ops/6-check-if-in-range/solution.md rename to 1-js/02-first-steps/11-logical-ops/6-check-if-in-range/solution.md diff --git a/1-js/2-first-steps/11-logical-ops/6-check-if-in-range/task.md b/1-js/02-first-steps/11-logical-ops/6-check-if-in-range/task.md similarity index 100% rename from 1-js/2-first-steps/11-logical-ops/6-check-if-in-range/task.md rename to 1-js/02-first-steps/11-logical-ops/6-check-if-in-range/task.md diff --git a/1-js/2-first-steps/11-logical-ops/7-check-if-out-range/solution.md b/1-js/02-first-steps/11-logical-ops/7-check-if-out-range/solution.md similarity index 100% rename from 1-js/2-first-steps/11-logical-ops/7-check-if-out-range/solution.md rename to 1-js/02-first-steps/11-logical-ops/7-check-if-out-range/solution.md diff --git a/1-js/2-first-steps/11-logical-ops/7-check-if-out-range/task.md b/1-js/02-first-steps/11-logical-ops/7-check-if-out-range/task.md similarity index 100% rename from 1-js/2-first-steps/11-logical-ops/7-check-if-out-range/task.md rename to 1-js/02-first-steps/11-logical-ops/7-check-if-out-range/task.md diff --git a/1-js/2-first-steps/11-logical-ops/8-if-question/solution.md b/1-js/02-first-steps/11-logical-ops/8-if-question/solution.md similarity index 100% rename from 1-js/2-first-steps/11-logical-ops/8-if-question/solution.md rename to 1-js/02-first-steps/11-logical-ops/8-if-question/solution.md diff --git a/1-js/2-first-steps/11-logical-ops/8-if-question/task.md b/1-js/02-first-steps/11-logical-ops/8-if-question/task.md similarity index 100% rename from 1-js/2-first-steps/11-logical-ops/8-if-question/task.md rename to 1-js/02-first-steps/11-logical-ops/8-if-question/task.md diff --git a/1-js/2-first-steps/11-logical-ops/article.md b/1-js/02-first-steps/11-logical-ops/article.md similarity index 100% rename from 1-js/2-first-steps/11-logical-ops/article.md rename to 1-js/02-first-steps/11-logical-ops/article.md diff --git a/1-js/2-first-steps/12-while-for/1-loop-last-value/solution.md b/1-js/02-first-steps/12-while-for/1-loop-last-value/solution.md similarity index 100% rename from 1-js/2-first-steps/12-while-for/1-loop-last-value/solution.md rename to 1-js/02-first-steps/12-while-for/1-loop-last-value/solution.md diff --git a/1-js/2-first-steps/12-while-for/1-loop-last-value/task.md b/1-js/02-first-steps/12-while-for/1-loop-last-value/task.md similarity index 100% rename from 1-js/2-first-steps/12-while-for/1-loop-last-value/task.md rename to 1-js/02-first-steps/12-while-for/1-loop-last-value/task.md diff --git a/1-js/2-first-steps/12-while-for/2-which-value-while/solution.md b/1-js/02-first-steps/12-while-for/2-which-value-while/solution.md similarity index 100% rename from 1-js/2-first-steps/12-while-for/2-which-value-while/solution.md rename to 1-js/02-first-steps/12-while-for/2-which-value-while/solution.md diff --git a/1-js/2-first-steps/12-while-for/2-which-value-while/task.md b/1-js/02-first-steps/12-while-for/2-which-value-while/task.md similarity index 100% rename from 1-js/2-first-steps/12-while-for/2-which-value-while/task.md rename to 1-js/02-first-steps/12-while-for/2-which-value-while/task.md diff --git a/1-js/2-first-steps/12-while-for/3-which-value-for/solution.md b/1-js/02-first-steps/12-while-for/3-which-value-for/solution.md similarity index 100% rename from 1-js/2-first-steps/12-while-for/3-which-value-for/solution.md rename to 1-js/02-first-steps/12-while-for/3-which-value-for/solution.md diff --git a/1-js/2-first-steps/12-while-for/3-which-value-for/task.md b/1-js/02-first-steps/12-while-for/3-which-value-for/task.md similarity index 100% rename from 1-js/2-first-steps/12-while-for/3-which-value-for/task.md rename to 1-js/02-first-steps/12-while-for/3-which-value-for/task.md diff --git a/1-js/2-first-steps/12-while-for/4-for-even/solution.md b/1-js/02-first-steps/12-while-for/4-for-even/solution.md similarity index 100% rename from 1-js/2-first-steps/12-while-for/4-for-even/solution.md rename to 1-js/02-first-steps/12-while-for/4-for-even/solution.md diff --git a/1-js/2-first-steps/12-while-for/4-for-even/task.md b/1-js/02-first-steps/12-while-for/4-for-even/task.md similarity index 100% rename from 1-js/2-first-steps/12-while-for/4-for-even/task.md rename to 1-js/02-first-steps/12-while-for/4-for-even/task.md diff --git a/1-js/2-first-steps/12-while-for/5-replace-for-while/solution.md b/1-js/02-first-steps/12-while-for/5-replace-for-while/solution.md similarity index 100% rename from 1-js/2-first-steps/12-while-for/5-replace-for-while/solution.md rename to 1-js/02-first-steps/12-while-for/5-replace-for-while/solution.md diff --git a/1-js/2-first-steps/12-while-for/5-replace-for-while/task.md b/1-js/02-first-steps/12-while-for/5-replace-for-while/task.md similarity index 100% rename from 1-js/2-first-steps/12-while-for/5-replace-for-while/task.md rename to 1-js/02-first-steps/12-while-for/5-replace-for-while/task.md diff --git a/1-js/2-first-steps/12-while-for/6-repeat-until-correct/solution.md b/1-js/02-first-steps/12-while-for/6-repeat-until-correct/solution.md similarity index 100% rename from 1-js/2-first-steps/12-while-for/6-repeat-until-correct/solution.md rename to 1-js/02-first-steps/12-while-for/6-repeat-until-correct/solution.md diff --git a/1-js/2-first-steps/12-while-for/6-repeat-until-correct/task.md b/1-js/02-first-steps/12-while-for/6-repeat-until-correct/task.md similarity index 100% rename from 1-js/2-first-steps/12-while-for/6-repeat-until-correct/task.md rename to 1-js/02-first-steps/12-while-for/6-repeat-until-correct/task.md diff --git a/1-js/2-first-steps/12-while-for/7-list-primes/solution.md b/1-js/02-first-steps/12-while-for/7-list-primes/solution.md similarity index 100% rename from 1-js/2-first-steps/12-while-for/7-list-primes/solution.md rename to 1-js/02-first-steps/12-while-for/7-list-primes/solution.md diff --git a/1-js/2-first-steps/12-while-for/7-list-primes/task.md b/1-js/02-first-steps/12-while-for/7-list-primes/task.md similarity index 100% rename from 1-js/2-first-steps/12-while-for/7-list-primes/task.md rename to 1-js/02-first-steps/12-while-for/7-list-primes/task.md diff --git a/1-js/2-first-steps/12-while-for/article.md b/1-js/02-first-steps/12-while-for/article.md similarity index 100% rename from 1-js/2-first-steps/12-while-for/article.md rename to 1-js/02-first-steps/12-while-for/article.md diff --git a/1-js/2-first-steps/13-switch/1-rewrite-switch-if-else/solution.md b/1-js/02-first-steps/13-switch/1-rewrite-switch-if-else/solution.md similarity index 100% rename from 1-js/2-first-steps/13-switch/1-rewrite-switch-if-else/solution.md rename to 1-js/02-first-steps/13-switch/1-rewrite-switch-if-else/solution.md diff --git a/1-js/2-first-steps/13-switch/1-rewrite-switch-if-else/task.md b/1-js/02-first-steps/13-switch/1-rewrite-switch-if-else/task.md similarity index 100% rename from 1-js/2-first-steps/13-switch/1-rewrite-switch-if-else/task.md rename to 1-js/02-first-steps/13-switch/1-rewrite-switch-if-else/task.md diff --git a/1-js/2-first-steps/13-switch/2-rewrite-if-switch/solution.md b/1-js/02-first-steps/13-switch/2-rewrite-if-switch/solution.md similarity index 100% rename from 1-js/2-first-steps/13-switch/2-rewrite-if-switch/solution.md rename to 1-js/02-first-steps/13-switch/2-rewrite-if-switch/solution.md diff --git a/1-js/2-first-steps/13-switch/2-rewrite-if-switch/task.md b/1-js/02-first-steps/13-switch/2-rewrite-if-switch/task.md similarity index 100% rename from 1-js/2-first-steps/13-switch/2-rewrite-if-switch/task.md rename to 1-js/02-first-steps/13-switch/2-rewrite-if-switch/task.md diff --git a/1-js/2-first-steps/13-switch/article.md b/1-js/02-first-steps/13-switch/article.md similarity index 100% rename from 1-js/2-first-steps/13-switch/article.md rename to 1-js/02-first-steps/13-switch/article.md diff --git a/1-js/2-first-steps/14-function-basics/1-if-else-required/solution.md b/1-js/02-first-steps/14-function-basics/1-if-else-required/solution.md similarity index 100% rename from 1-js/2-first-steps/14-function-basics/1-if-else-required/solution.md rename to 1-js/02-first-steps/14-function-basics/1-if-else-required/solution.md diff --git a/1-js/2-first-steps/14-function-basics/1-if-else-required/task.md b/1-js/02-first-steps/14-function-basics/1-if-else-required/task.md similarity index 100% rename from 1-js/2-first-steps/14-function-basics/1-if-else-required/task.md rename to 1-js/02-first-steps/14-function-basics/1-if-else-required/task.md diff --git a/1-js/2-first-steps/14-function-basics/2-rewrite-function-question-or/solution.md b/1-js/02-first-steps/14-function-basics/2-rewrite-function-question-or/solution.md similarity index 100% rename from 1-js/2-first-steps/14-function-basics/2-rewrite-function-question-or/solution.md rename to 1-js/02-first-steps/14-function-basics/2-rewrite-function-question-or/solution.md diff --git a/1-js/2-first-steps/14-function-basics/2-rewrite-function-question-or/task.md b/1-js/02-first-steps/14-function-basics/2-rewrite-function-question-or/task.md similarity index 100% rename from 1-js/2-first-steps/14-function-basics/2-rewrite-function-question-or/task.md rename to 1-js/02-first-steps/14-function-basics/2-rewrite-function-question-or/task.md diff --git a/1-js/2-first-steps/14-function-basics/3-min/solution.md b/1-js/02-first-steps/14-function-basics/3-min/solution.md similarity index 100% rename from 1-js/2-first-steps/14-function-basics/3-min/solution.md rename to 1-js/02-first-steps/14-function-basics/3-min/solution.md diff --git a/1-js/2-first-steps/14-function-basics/3-min/task.md b/1-js/02-first-steps/14-function-basics/3-min/task.md similarity index 100% rename from 1-js/2-first-steps/14-function-basics/3-min/task.md rename to 1-js/02-first-steps/14-function-basics/3-min/task.md diff --git a/1-js/2-first-steps/14-function-basics/4-pow/solution.md b/1-js/02-first-steps/14-function-basics/4-pow/solution.md similarity index 100% rename from 1-js/2-first-steps/14-function-basics/4-pow/solution.md rename to 1-js/02-first-steps/14-function-basics/4-pow/solution.md diff --git a/1-js/2-first-steps/14-function-basics/4-pow/task.md b/1-js/02-first-steps/14-function-basics/4-pow/task.md similarity index 100% rename from 1-js/2-first-steps/14-function-basics/4-pow/task.md rename to 1-js/02-first-steps/14-function-basics/4-pow/task.md diff --git a/1-js/2-first-steps/14-function-basics/article.md b/1-js/02-first-steps/14-function-basics/article.md similarity index 100% rename from 1-js/2-first-steps/14-function-basics/article.md rename to 1-js/02-first-steps/14-function-basics/article.md diff --git a/1-js/2-first-steps/14-function-basics/function_basics.png b/1-js/02-first-steps/14-function-basics/function_basics.png similarity index 100% rename from 1-js/2-first-steps/14-function-basics/function_basics.png rename to 1-js/02-first-steps/14-function-basics/function_basics.png diff --git a/1-js/2-first-steps/14-function-basics/function_basics@2x.png b/1-js/02-first-steps/14-function-basics/function_basics@2x.png similarity index 100% rename from 1-js/2-first-steps/14-function-basics/function_basics@2x.png rename to 1-js/02-first-steps/14-function-basics/function_basics@2x.png diff --git a/1-js/2-first-steps/15-function-expressions-arrows/article.md b/1-js/02-first-steps/15-function-expressions-arrows/article.md similarity index 100% rename from 1-js/2-first-steps/15-function-expressions-arrows/article.md rename to 1-js/02-first-steps/15-function-expressions-arrows/article.md diff --git a/1-js/2-first-steps/16-javascript-specials/article.md b/1-js/02-first-steps/16-javascript-specials/article.md similarity index 100% rename from 1-js/2-first-steps/16-javascript-specials/article.md rename to 1-js/02-first-steps/16-javascript-specials/article.md diff --git a/1-js/2-first-steps/index.md b/1-js/02-first-steps/index.md similarity index 100% rename from 1-js/2-first-steps/index.md rename to 1-js/02-first-steps/index.md diff --git a/1-js/3-code-quality/1-debugging-chrome/article.md b/1-js/03-code-quality/1-debugging-chrome/article.md similarity index 100% rename from 1-js/3-code-quality/1-debugging-chrome/article.md rename to 1-js/03-code-quality/1-debugging-chrome/article.md diff --git a/1-js/3-code-quality/1-debugging-chrome/chrome_break_error.png b/1-js/03-code-quality/1-debugging-chrome/chrome_break_error.png similarity index 100% rename from 1-js/3-code-quality/1-debugging-chrome/chrome_break_error.png rename to 1-js/03-code-quality/1-debugging-chrome/chrome_break_error.png diff --git a/1-js/3-code-quality/1-debugging-chrome/chrome_break_error@2x.png b/1-js/03-code-quality/1-debugging-chrome/chrome_break_error@2x.png similarity index 100% rename from 1-js/3-code-quality/1-debugging-chrome/chrome_break_error@2x.png rename to 1-js/03-code-quality/1-debugging-chrome/chrome_break_error@2x.png diff --git a/1-js/3-code-quality/1-debugging-chrome/chrome_sources.png b/1-js/03-code-quality/1-debugging-chrome/chrome_sources.png similarity index 100% rename from 1-js/3-code-quality/1-debugging-chrome/chrome_sources.png rename to 1-js/03-code-quality/1-debugging-chrome/chrome_sources.png diff --git a/1-js/3-code-quality/1-debugging-chrome/chrome_sources@2x.png b/1-js/03-code-quality/1-debugging-chrome/chrome_sources@2x.png similarity index 100% rename from 1-js/3-code-quality/1-debugging-chrome/chrome_sources@2x.png rename to 1-js/03-code-quality/1-debugging-chrome/chrome_sources@2x.png diff --git a/1-js/3-code-quality/1-debugging-chrome/chrome_sources_break.png b/1-js/03-code-quality/1-debugging-chrome/chrome_sources_break.png similarity index 100% rename from 1-js/3-code-quality/1-debugging-chrome/chrome_sources_break.png rename to 1-js/03-code-quality/1-debugging-chrome/chrome_sources_break.png diff --git a/1-js/3-code-quality/1-debugging-chrome/chrome_sources_break@2x.png b/1-js/03-code-quality/1-debugging-chrome/chrome_sources_break@2x.png similarity index 100% rename from 1-js/3-code-quality/1-debugging-chrome/chrome_sources_break@2x.png rename to 1-js/03-code-quality/1-debugging-chrome/chrome_sources_break@2x.png diff --git a/1-js/3-code-quality/1-debugging-chrome/chrome_sources_breakpoint.png b/1-js/03-code-quality/1-debugging-chrome/chrome_sources_breakpoint.png similarity index 100% rename from 1-js/3-code-quality/1-debugging-chrome/chrome_sources_breakpoint.png rename to 1-js/03-code-quality/1-debugging-chrome/chrome_sources_breakpoint.png diff --git a/1-js/3-code-quality/1-debugging-chrome/chrome_sources_breakpoint@2x.png b/1-js/03-code-quality/1-debugging-chrome/chrome_sources_breakpoint@2x.png similarity index 100% rename from 1-js/3-code-quality/1-debugging-chrome/chrome_sources_breakpoint@2x.png rename to 1-js/03-code-quality/1-debugging-chrome/chrome_sources_breakpoint@2x.png diff --git a/1-js/3-code-quality/1-debugging-chrome/chrome_sources_buttons.png b/1-js/03-code-quality/1-debugging-chrome/chrome_sources_buttons.png similarity index 100% rename from 1-js/3-code-quality/1-debugging-chrome/chrome_sources_buttons.png rename to 1-js/03-code-quality/1-debugging-chrome/chrome_sources_buttons.png diff --git a/1-js/3-code-quality/1-debugging-chrome/chrome_sources_buttons@2x.png b/1-js/03-code-quality/1-debugging-chrome/chrome_sources_buttons@2x.png similarity index 100% rename from 1-js/3-code-quality/1-debugging-chrome/chrome_sources_buttons@2x.png rename to 1-js/03-code-quality/1-debugging-chrome/chrome_sources_buttons@2x.png diff --git a/1-js/3-code-quality/1-debugging-chrome/console_error.png b/1-js/03-code-quality/1-debugging-chrome/console_error.png similarity index 100% rename from 1-js/3-code-quality/1-debugging-chrome/console_error.png rename to 1-js/03-code-quality/1-debugging-chrome/console_error.png diff --git a/1-js/3-code-quality/1-debugging-chrome/console_error@2x.png b/1-js/03-code-quality/1-debugging-chrome/console_error@2x.png similarity index 100% rename from 1-js/3-code-quality/1-debugging-chrome/console_error@2x.png rename to 1-js/03-code-quality/1-debugging-chrome/console_error@2x.png diff --git a/1-js/3-code-quality/1-debugging-chrome/debugging.view/index.html b/1-js/03-code-quality/1-debugging-chrome/debugging.view/index.html similarity index 100% rename from 1-js/3-code-quality/1-debugging-chrome/debugging.view/index.html rename to 1-js/03-code-quality/1-debugging-chrome/debugging.view/index.html diff --git a/1-js/3-code-quality/1-debugging-chrome/debugging.view/pow.js b/1-js/03-code-quality/1-debugging-chrome/debugging.view/pow.js similarity index 100% rename from 1-js/3-code-quality/1-debugging-chrome/debugging.view/pow.js rename to 1-js/03-code-quality/1-debugging-chrome/debugging.view/pow.js diff --git a/1-js/3-code-quality/1-debugging-chrome/error.view/index.html b/1-js/03-code-quality/1-debugging-chrome/error.view/index.html similarity index 100% rename from 1-js/3-code-quality/1-debugging-chrome/error.view/index.html rename to 1-js/03-code-quality/1-debugging-chrome/error.view/index.html diff --git a/1-js/3-code-quality/1-debugging-chrome/error.view/pow.js b/1-js/03-code-quality/1-debugging-chrome/error.view/pow.js similarity index 100% rename from 1-js/3-code-quality/1-debugging-chrome/error.view/pow.js rename to 1-js/03-code-quality/1-debugging-chrome/error.view/pow.js diff --git a/1-js/3-code-quality/1-debugging-chrome/head.html b/1-js/03-code-quality/1-debugging-chrome/head.html similarity index 100% rename from 1-js/3-code-quality/1-debugging-chrome/head.html rename to 1-js/03-code-quality/1-debugging-chrome/head.html diff --git a/1-js/3-code-quality/1-debugging-chrome/manage1.png b/1-js/03-code-quality/1-debugging-chrome/manage1.png similarity index 100% rename from 1-js/3-code-quality/1-debugging-chrome/manage1.png rename to 1-js/03-code-quality/1-debugging-chrome/manage1.png diff --git a/1-js/3-code-quality/1-debugging-chrome/manage1@2x.png b/1-js/03-code-quality/1-debugging-chrome/manage1@2x.png similarity index 100% rename from 1-js/3-code-quality/1-debugging-chrome/manage1@2x.png rename to 1-js/03-code-quality/1-debugging-chrome/manage1@2x.png diff --git a/1-js/3-code-quality/1-debugging-chrome/manage2.png b/1-js/03-code-quality/1-debugging-chrome/manage2.png similarity index 100% rename from 1-js/3-code-quality/1-debugging-chrome/manage2.png rename to 1-js/03-code-quality/1-debugging-chrome/manage2.png diff --git a/1-js/3-code-quality/1-debugging-chrome/manage2@2x.png b/1-js/03-code-quality/1-debugging-chrome/manage2@2x.png similarity index 100% rename from 1-js/3-code-quality/1-debugging-chrome/manage2@2x.png rename to 1-js/03-code-quality/1-debugging-chrome/manage2@2x.png diff --git a/1-js/3-code-quality/1-debugging-chrome/manage3.png b/1-js/03-code-quality/1-debugging-chrome/manage3.png similarity index 100% rename from 1-js/3-code-quality/1-debugging-chrome/manage3.png rename to 1-js/03-code-quality/1-debugging-chrome/manage3.png diff --git a/1-js/3-code-quality/1-debugging-chrome/manage3@2x.png b/1-js/03-code-quality/1-debugging-chrome/manage3@2x.png similarity index 100% rename from 1-js/3-code-quality/1-debugging-chrome/manage3@2x.png rename to 1-js/03-code-quality/1-debugging-chrome/manage3@2x.png diff --git a/1-js/3-code-quality/1-debugging-chrome/manage4.png b/1-js/03-code-quality/1-debugging-chrome/manage4.png similarity index 100% rename from 1-js/3-code-quality/1-debugging-chrome/manage4.png rename to 1-js/03-code-quality/1-debugging-chrome/manage4.png diff --git a/1-js/3-code-quality/1-debugging-chrome/manage4@2x.png b/1-js/03-code-quality/1-debugging-chrome/manage4@2x.png similarity index 100% rename from 1-js/3-code-quality/1-debugging-chrome/manage4@2x.png rename to 1-js/03-code-quality/1-debugging-chrome/manage4@2x.png diff --git a/1-js/3-code-quality/1-debugging-chrome/manage5.png b/1-js/03-code-quality/1-debugging-chrome/manage5.png similarity index 100% rename from 1-js/3-code-quality/1-debugging-chrome/manage5.png rename to 1-js/03-code-quality/1-debugging-chrome/manage5.png diff --git a/1-js/3-code-quality/1-debugging-chrome/manage5@2x.png b/1-js/03-code-quality/1-debugging-chrome/manage5@2x.png similarity index 100% rename from 1-js/3-code-quality/1-debugging-chrome/manage5@2x.png rename to 1-js/03-code-quality/1-debugging-chrome/manage5@2x.png diff --git a/1-js/3-code-quality/1-debugging-chrome/manage6.png b/1-js/03-code-quality/1-debugging-chrome/manage6.png similarity index 100% rename from 1-js/3-code-quality/1-debugging-chrome/manage6.png rename to 1-js/03-code-quality/1-debugging-chrome/manage6.png diff --git a/1-js/3-code-quality/1-debugging-chrome/manage6@2x.png b/1-js/03-code-quality/1-debugging-chrome/manage6@2x.png similarity index 100% rename from 1-js/3-code-quality/1-debugging-chrome/manage6@2x.png rename to 1-js/03-code-quality/1-debugging-chrome/manage6@2x.png diff --git a/1-js/3-code-quality/1-debugging-chrome/statusbarButtonGlyphs.svg b/1-js/03-code-quality/1-debugging-chrome/statusbarButtonGlyphs.svg similarity index 100% rename from 1-js/3-code-quality/1-debugging-chrome/statusbarButtonGlyphs.svg rename to 1-js/03-code-quality/1-debugging-chrome/statusbarButtonGlyphs.svg diff --git a/1-js/3-code-quality/2-coding-style/1-style-errors/solution.md b/1-js/03-code-quality/2-coding-style/1-style-errors/solution.md similarity index 100% rename from 1-js/3-code-quality/2-coding-style/1-style-errors/solution.md rename to 1-js/03-code-quality/2-coding-style/1-style-errors/solution.md diff --git a/1-js/3-code-quality/2-coding-style/1-style-errors/task.md b/1-js/03-code-quality/2-coding-style/1-style-errors/task.md similarity index 100% rename from 1-js/3-code-quality/2-coding-style/1-style-errors/task.md rename to 1-js/03-code-quality/2-coding-style/1-style-errors/task.md diff --git a/1-js/3-code-quality/2-coding-style/article.md b/1-js/03-code-quality/2-coding-style/article.md similarity index 100% rename from 1-js/3-code-quality/2-coding-style/article.md rename to 1-js/03-code-quality/2-coding-style/article.md diff --git a/1-js/3-code-quality/2-coding-style/code-style.png b/1-js/03-code-quality/2-coding-style/code-style.png similarity index 100% rename from 1-js/3-code-quality/2-coding-style/code-style.png rename to 1-js/03-code-quality/2-coding-style/code-style.png diff --git a/1-js/3-code-quality/2-coding-style/code-style@2x.png b/1-js/03-code-quality/2-coding-style/code-style@2x.png similarity index 100% rename from 1-js/3-code-quality/2-coding-style/code-style@2x.png rename to 1-js/03-code-quality/2-coding-style/code-style@2x.png diff --git a/1-js/3-code-quality/2-coding-style/figure-bracket-style.png b/1-js/03-code-quality/2-coding-style/figure-bracket-style.png similarity index 100% rename from 1-js/3-code-quality/2-coding-style/figure-bracket-style.png rename to 1-js/03-code-quality/2-coding-style/figure-bracket-style.png diff --git a/1-js/3-code-quality/2-coding-style/figure-bracket-style@2x.png b/1-js/03-code-quality/2-coding-style/figure-bracket-style@2x.png similarity index 100% rename from 1-js/3-code-quality/2-coding-style/figure-bracket-style@2x.png rename to 1-js/03-code-quality/2-coding-style/figure-bracket-style@2x.png diff --git a/1-js/3-code-quality/3-write-unmain-code/article.md b/1-js/03-code-quality/3-write-unmain-code/article.md similarity index 100% rename from 1-js/3-code-quality/3-write-unmain-code/article.md rename to 1-js/03-code-quality/3-write-unmain-code/article.md diff --git a/1-js/3-code-quality/4-testing/1-pow-nan-spec/_js.view/solution.js b/1-js/03-code-quality/4-testing/1-pow-nan-spec/_js.view/solution.js similarity index 100% rename from 1-js/3-code-quality/4-testing/1-pow-nan-spec/_js.view/solution.js rename to 1-js/03-code-quality/4-testing/1-pow-nan-spec/_js.view/solution.js diff --git a/1-js/3-code-quality/4-testing/1-pow-nan-spec/_js.view/source.js b/1-js/03-code-quality/4-testing/1-pow-nan-spec/_js.view/source.js similarity index 100% rename from 1-js/3-code-quality/4-testing/1-pow-nan-spec/_js.view/source.js rename to 1-js/03-code-quality/4-testing/1-pow-nan-spec/_js.view/source.js diff --git a/1-js/3-code-quality/4-testing/1-pow-nan-spec/_js.view/test.js b/1-js/03-code-quality/4-testing/1-pow-nan-spec/_js.view/test.js similarity index 100% rename from 1-js/3-code-quality/4-testing/1-pow-nan-spec/_js.view/test.js rename to 1-js/03-code-quality/4-testing/1-pow-nan-spec/_js.view/test.js diff --git a/1-js/3-code-quality/4-testing/1-pow-nan-spec/solution.md b/1-js/03-code-quality/4-testing/1-pow-nan-spec/solution.md similarity index 100% rename from 1-js/3-code-quality/4-testing/1-pow-nan-spec/solution.md rename to 1-js/03-code-quality/4-testing/1-pow-nan-spec/solution.md diff --git a/1-js/3-code-quality/4-testing/1-pow-nan-spec/task.md b/1-js/03-code-quality/4-testing/1-pow-nan-spec/task.md similarity index 100% rename from 1-js/3-code-quality/4-testing/1-pow-nan-spec/task.md rename to 1-js/03-code-quality/4-testing/1-pow-nan-spec/task.md diff --git a/1-js/3-code-quality/4-testing/2-pow-test-0/solution.md b/1-js/03-code-quality/4-testing/2-pow-test-0/solution.md similarity index 100% rename from 1-js/3-code-quality/4-testing/2-pow-test-0/solution.md rename to 1-js/03-code-quality/4-testing/2-pow-test-0/solution.md diff --git a/1-js/3-code-quality/4-testing/2-pow-test-0/solution.view/index.html b/1-js/03-code-quality/4-testing/2-pow-test-0/solution.view/index.html similarity index 100% rename from 1-js/3-code-quality/4-testing/2-pow-test-0/solution.view/index.html rename to 1-js/03-code-quality/4-testing/2-pow-test-0/solution.view/index.html diff --git a/1-js/3-code-quality/4-testing/2-pow-test-0/solution.view/test.js b/1-js/03-code-quality/4-testing/2-pow-test-0/solution.view/test.js similarity index 100% rename from 1-js/3-code-quality/4-testing/2-pow-test-0/solution.view/test.js rename to 1-js/03-code-quality/4-testing/2-pow-test-0/solution.view/test.js diff --git a/1-js/3-code-quality/4-testing/2-pow-test-0/source.view/index.html b/1-js/03-code-quality/4-testing/2-pow-test-0/source.view/index.html similarity index 100% rename from 1-js/3-code-quality/4-testing/2-pow-test-0/source.view/index.html rename to 1-js/03-code-quality/4-testing/2-pow-test-0/source.view/index.html diff --git a/1-js/3-code-quality/4-testing/2-pow-test-0/source.view/test.js b/1-js/03-code-quality/4-testing/2-pow-test-0/source.view/test.js similarity index 100% rename from 1-js/3-code-quality/4-testing/2-pow-test-0/source.view/test.js rename to 1-js/03-code-quality/4-testing/2-pow-test-0/source.view/test.js diff --git a/1-js/3-code-quality/4-testing/2-pow-test-0/task.md b/1-js/03-code-quality/4-testing/2-pow-test-0/task.md similarity index 100% rename from 1-js/3-code-quality/4-testing/2-pow-test-0/task.md rename to 1-js/03-code-quality/4-testing/2-pow-test-0/task.md diff --git a/1-js/3-code-quality/4-testing/3-pow-test-wrong/solution.md b/1-js/03-code-quality/4-testing/3-pow-test-wrong/solution.md similarity index 100% rename from 1-js/3-code-quality/4-testing/3-pow-test-wrong/solution.md rename to 1-js/03-code-quality/4-testing/3-pow-test-wrong/solution.md diff --git a/1-js/3-code-quality/4-testing/3-pow-test-wrong/task.md b/1-js/03-code-quality/4-testing/3-pow-test-wrong/task.md similarity index 100% rename from 1-js/3-code-quality/4-testing/3-pow-test-wrong/task.md rename to 1-js/03-code-quality/4-testing/3-pow-test-wrong/task.md diff --git a/1-js/3-code-quality/4-testing/article.md b/1-js/03-code-quality/4-testing/article.md similarity index 100% rename from 1-js/3-code-quality/4-testing/article.md rename to 1-js/03-code-quality/4-testing/article.md diff --git a/1-js/3-code-quality/4-testing/beforeafter.view/index.html b/1-js/03-code-quality/4-testing/beforeafter.view/index.html similarity index 100% rename from 1-js/3-code-quality/4-testing/beforeafter.view/index.html rename to 1-js/03-code-quality/4-testing/beforeafter.view/index.html diff --git a/1-js/3-code-quality/4-testing/beforeafter.view/test.js b/1-js/03-code-quality/4-testing/beforeafter.view/test.js similarity index 100% rename from 1-js/3-code-quality/4-testing/beforeafter.view/test.js rename to 1-js/03-code-quality/4-testing/beforeafter.view/test.js diff --git a/1-js/3-code-quality/4-testing/index.html b/1-js/03-code-quality/4-testing/index.html similarity index 100% rename from 1-js/3-code-quality/4-testing/index.html rename to 1-js/03-code-quality/4-testing/index.html diff --git a/1-js/3-code-quality/4-testing/pow-1.view/index.html b/1-js/03-code-quality/4-testing/pow-1.view/index.html similarity index 100% rename from 1-js/3-code-quality/4-testing/pow-1.view/index.html rename to 1-js/03-code-quality/4-testing/pow-1.view/index.html diff --git a/1-js/3-code-quality/4-testing/pow-1.view/test.js b/1-js/03-code-quality/4-testing/pow-1.view/test.js similarity index 100% rename from 1-js/3-code-quality/4-testing/pow-1.view/test.js rename to 1-js/03-code-quality/4-testing/pow-1.view/test.js diff --git a/1-js/3-code-quality/4-testing/pow-2.view/index.html b/1-js/03-code-quality/4-testing/pow-2.view/index.html similarity index 100% rename from 1-js/3-code-quality/4-testing/pow-2.view/index.html rename to 1-js/03-code-quality/4-testing/pow-2.view/index.html diff --git a/1-js/3-code-quality/4-testing/pow-2.view/test.js b/1-js/03-code-quality/4-testing/pow-2.view/test.js similarity index 100% rename from 1-js/3-code-quality/4-testing/pow-2.view/test.js rename to 1-js/03-code-quality/4-testing/pow-2.view/test.js diff --git a/1-js/3-code-quality/4-testing/pow-3.view/index.html b/1-js/03-code-quality/4-testing/pow-3.view/index.html similarity index 100% rename from 1-js/3-code-quality/4-testing/pow-3.view/index.html rename to 1-js/03-code-quality/4-testing/pow-3.view/index.html diff --git a/1-js/3-code-quality/4-testing/pow-3.view/test.js b/1-js/03-code-quality/4-testing/pow-3.view/test.js similarity index 100% rename from 1-js/3-code-quality/4-testing/pow-3.view/test.js rename to 1-js/03-code-quality/4-testing/pow-3.view/test.js diff --git a/1-js/3-code-quality/4-testing/pow-4.view/index.html b/1-js/03-code-quality/4-testing/pow-4.view/index.html similarity index 100% rename from 1-js/3-code-quality/4-testing/pow-4.view/index.html rename to 1-js/03-code-quality/4-testing/pow-4.view/index.html diff --git a/1-js/3-code-quality/4-testing/pow-4.view/test.js b/1-js/03-code-quality/4-testing/pow-4.view/test.js similarity index 100% rename from 1-js/3-code-quality/4-testing/pow-4.view/test.js rename to 1-js/03-code-quality/4-testing/pow-4.view/test.js diff --git a/1-js/3-code-quality/4-testing/pow-full.view/index.html b/1-js/03-code-quality/4-testing/pow-full.view/index.html similarity index 100% rename from 1-js/3-code-quality/4-testing/pow-full.view/index.html rename to 1-js/03-code-quality/4-testing/pow-full.view/index.html diff --git a/1-js/3-code-quality/4-testing/pow-full.view/test.js b/1-js/03-code-quality/4-testing/pow-full.view/test.js similarity index 100% rename from 1-js/3-code-quality/4-testing/pow-full.view/test.js rename to 1-js/03-code-quality/4-testing/pow-full.view/test.js diff --git a/1-js/3-code-quality/4-testing/pow-min.view/index.html b/1-js/03-code-quality/4-testing/pow-min.view/index.html similarity index 100% rename from 1-js/3-code-quality/4-testing/pow-min.view/index.html rename to 1-js/03-code-quality/4-testing/pow-min.view/index.html diff --git a/1-js/3-code-quality/4-testing/pow-min.view/test.js b/1-js/03-code-quality/4-testing/pow-min.view/test.js similarity index 100% rename from 1-js/3-code-quality/4-testing/pow-min.view/test.js rename to 1-js/03-code-quality/4-testing/pow-min.view/test.js diff --git a/1-js/3-code-quality/4-testing/pow-nan-assert.view/index.html b/1-js/03-code-quality/4-testing/pow-nan-assert.view/index.html similarity index 100% rename from 1-js/3-code-quality/4-testing/pow-nan-assert.view/index.html rename to 1-js/03-code-quality/4-testing/pow-nan-assert.view/index.html diff --git a/1-js/3-code-quality/4-testing/pow-nan-assert.view/test.js b/1-js/03-code-quality/4-testing/pow-nan-assert.view/test.js similarity index 100% rename from 1-js/3-code-quality/4-testing/pow-nan-assert.view/test.js rename to 1-js/03-code-quality/4-testing/pow-nan-assert.view/test.js diff --git a/1-js/3-code-quality/4-testing/pow-nan.view/index.html b/1-js/03-code-quality/4-testing/pow-nan.view/index.html similarity index 100% rename from 1-js/3-code-quality/4-testing/pow-nan.view/index.html rename to 1-js/03-code-quality/4-testing/pow-nan.view/index.html diff --git a/1-js/3-code-quality/4-testing/pow-nan.view/test.js b/1-js/03-code-quality/4-testing/pow-nan.view/test.js similarity index 100% rename from 1-js/3-code-quality/4-testing/pow-nan.view/test.js rename to 1-js/03-code-quality/4-testing/pow-nan.view/test.js diff --git a/1-js/3-code-quality/5-polyfills/article.md b/1-js/03-code-quality/5-polyfills/article.md similarity index 100% rename from 1-js/3-code-quality/5-polyfills/article.md rename to 1-js/03-code-quality/5-polyfills/article.md diff --git a/1-js/3-code-quality/index.md b/1-js/03-code-quality/index.md similarity index 100% rename from 1-js/3-code-quality/index.md rename to 1-js/03-code-quality/index.md diff --git a/1-js/4-object-basics/01-object/2-hello-object/solution.md b/1-js/04-object-basics/01-object/2-hello-object/solution.md similarity index 100% rename from 1-js/4-object-basics/01-object/2-hello-object/solution.md rename to 1-js/04-object-basics/01-object/2-hello-object/solution.md diff --git a/1-js/4-object-basics/01-object/2-hello-object/task.md b/1-js/04-object-basics/01-object/2-hello-object/task.md similarity index 100% rename from 1-js/4-object-basics/01-object/2-hello-object/task.md rename to 1-js/04-object-basics/01-object/2-hello-object/task.md diff --git a/1-js/4-object-basics/01-object/3-is-empty/_js.view/solution.js b/1-js/04-object-basics/01-object/3-is-empty/_js.view/solution.js similarity index 100% rename from 1-js/4-object-basics/01-object/3-is-empty/_js.view/solution.js rename to 1-js/04-object-basics/01-object/3-is-empty/_js.view/solution.js diff --git a/1-js/4-object-basics/01-object/3-is-empty/_js.view/test.js b/1-js/04-object-basics/01-object/3-is-empty/_js.view/test.js similarity index 100% rename from 1-js/4-object-basics/01-object/3-is-empty/_js.view/test.js rename to 1-js/04-object-basics/01-object/3-is-empty/_js.view/test.js diff --git a/1-js/4-object-basics/01-object/3-is-empty/solution.md b/1-js/04-object-basics/01-object/3-is-empty/solution.md similarity index 100% rename from 1-js/4-object-basics/01-object/3-is-empty/solution.md rename to 1-js/04-object-basics/01-object/3-is-empty/solution.md diff --git a/1-js/4-object-basics/01-object/3-is-empty/task.md b/1-js/04-object-basics/01-object/3-is-empty/task.md similarity index 100% rename from 1-js/4-object-basics/01-object/3-is-empty/task.md rename to 1-js/04-object-basics/01-object/3-is-empty/task.md diff --git a/1-js/4-object-basics/01-object/4-const-object/solution.md b/1-js/04-object-basics/01-object/4-const-object/solution.md similarity index 100% rename from 1-js/4-object-basics/01-object/4-const-object/solution.md rename to 1-js/04-object-basics/01-object/4-const-object/solution.md diff --git a/1-js/4-object-basics/01-object/4-const-object/task.md b/1-js/04-object-basics/01-object/4-const-object/task.md similarity index 100% rename from 1-js/4-object-basics/01-object/4-const-object/task.md rename to 1-js/04-object-basics/01-object/4-const-object/task.md diff --git a/1-js/4-object-basics/01-object/5-sum-object/solution.md b/1-js/04-object-basics/01-object/5-sum-object/solution.md similarity index 100% rename from 1-js/4-object-basics/01-object/5-sum-object/solution.md rename to 1-js/04-object-basics/01-object/5-sum-object/solution.md diff --git a/1-js/4-object-basics/01-object/5-sum-object/task.md b/1-js/04-object-basics/01-object/5-sum-object/task.md similarity index 100% rename from 1-js/4-object-basics/01-object/5-sum-object/task.md rename to 1-js/04-object-basics/01-object/5-sum-object/task.md diff --git a/1-js/4-object-basics/01-object/8-multiply-numeric/_js.view/solution.js b/1-js/04-object-basics/01-object/8-multiply-numeric/_js.view/solution.js similarity index 100% rename from 1-js/4-object-basics/01-object/8-multiply-numeric/_js.view/solution.js rename to 1-js/04-object-basics/01-object/8-multiply-numeric/_js.view/solution.js diff --git a/1-js/4-object-basics/01-object/8-multiply-numeric/_js.view/source.js b/1-js/04-object-basics/01-object/8-multiply-numeric/_js.view/source.js similarity index 100% rename from 1-js/4-object-basics/01-object/8-multiply-numeric/_js.view/source.js rename to 1-js/04-object-basics/01-object/8-multiply-numeric/_js.view/source.js diff --git a/1-js/4-object-basics/01-object/8-multiply-numeric/_js.view/test.js b/1-js/04-object-basics/01-object/8-multiply-numeric/_js.view/test.js similarity index 100% rename from 1-js/4-object-basics/01-object/8-multiply-numeric/_js.view/test.js rename to 1-js/04-object-basics/01-object/8-multiply-numeric/_js.view/test.js diff --git a/1-js/4-object-basics/01-object/8-multiply-numeric/solution.md b/1-js/04-object-basics/01-object/8-multiply-numeric/solution.md similarity index 100% rename from 1-js/4-object-basics/01-object/8-multiply-numeric/solution.md rename to 1-js/04-object-basics/01-object/8-multiply-numeric/solution.md diff --git a/1-js/4-object-basics/01-object/8-multiply-numeric/task.md b/1-js/04-object-basics/01-object/8-multiply-numeric/task.md similarity index 100% rename from 1-js/4-object-basics/01-object/8-multiply-numeric/task.md rename to 1-js/04-object-basics/01-object/8-multiply-numeric/task.md diff --git a/1-js/4-object-basics/01-object/article.md b/1-js/04-object-basics/01-object/article.md similarity index 100% rename from 1-js/4-object-basics/01-object/article.md rename to 1-js/04-object-basics/01-object/article.md diff --git a/1-js/4-object-basics/01-object/object-user-delete.png b/1-js/04-object-basics/01-object/object-user-delete.png similarity index 100% rename from 1-js/4-object-basics/01-object/object-user-delete.png rename to 1-js/04-object-basics/01-object/object-user-delete.png diff --git a/1-js/4-object-basics/01-object/object-user-delete@2x.png b/1-js/04-object-basics/01-object/object-user-delete@2x.png similarity index 100% rename from 1-js/4-object-basics/01-object/object-user-delete@2x.png rename to 1-js/04-object-basics/01-object/object-user-delete@2x.png diff --git a/1-js/4-object-basics/01-object/object-user-empty.png b/1-js/04-object-basics/01-object/object-user-empty.png similarity index 100% rename from 1-js/4-object-basics/01-object/object-user-empty.png rename to 1-js/04-object-basics/01-object/object-user-empty.png diff --git a/1-js/4-object-basics/01-object/object-user-empty@2x.png b/1-js/04-object-basics/01-object/object-user-empty@2x.png similarity index 100% rename from 1-js/4-object-basics/01-object/object-user-empty@2x.png rename to 1-js/04-object-basics/01-object/object-user-empty@2x.png diff --git a/1-js/4-object-basics/01-object/object-user-isadmin.png b/1-js/04-object-basics/01-object/object-user-isadmin.png similarity index 100% rename from 1-js/4-object-basics/01-object/object-user-isadmin.png rename to 1-js/04-object-basics/01-object/object-user-isadmin.png diff --git a/1-js/4-object-basics/01-object/object-user-isadmin@2x.png b/1-js/04-object-basics/01-object/object-user-isadmin@2x.png similarity index 100% rename from 1-js/4-object-basics/01-object/object-user-isadmin@2x.png rename to 1-js/04-object-basics/01-object/object-user-isadmin@2x.png diff --git a/1-js/4-object-basics/01-object/object-user-props.png b/1-js/04-object-basics/01-object/object-user-props.png similarity index 100% rename from 1-js/4-object-basics/01-object/object-user-props.png rename to 1-js/04-object-basics/01-object/object-user-props.png diff --git a/1-js/4-object-basics/01-object/object-user-props@2x.png b/1-js/04-object-basics/01-object/object-user-props@2x.png similarity index 100% rename from 1-js/4-object-basics/01-object/object-user-props@2x.png rename to 1-js/04-object-basics/01-object/object-user-props@2x.png diff --git a/1-js/4-object-basics/01-object/object-user.png b/1-js/04-object-basics/01-object/object-user.png similarity index 100% rename from 1-js/4-object-basics/01-object/object-user.png rename to 1-js/04-object-basics/01-object/object-user.png diff --git a/1-js/4-object-basics/01-object/object-user@2x.png b/1-js/04-object-basics/01-object/object-user@2x.png similarity index 100% rename from 1-js/4-object-basics/01-object/object-user@2x.png rename to 1-js/04-object-basics/01-object/object-user@2x.png diff --git a/1-js/4-object-basics/01-object/object.png b/1-js/04-object-basics/01-object/object.png similarity index 100% rename from 1-js/4-object-basics/01-object/object.png rename to 1-js/04-object-basics/01-object/object.png diff --git a/1-js/4-object-basics/01-object/object@2x.png b/1-js/04-object-basics/01-object/object@2x.png similarity index 100% rename from 1-js/4-object-basics/01-object/object@2x.png rename to 1-js/04-object-basics/01-object/object@2x.png diff --git a/1-js/4-object-basics/01-object/variable-contains-reference.png b/1-js/04-object-basics/01-object/variable-contains-reference.png similarity index 100% rename from 1-js/4-object-basics/01-object/variable-contains-reference.png rename to 1-js/04-object-basics/01-object/variable-contains-reference.png diff --git a/1-js/4-object-basics/01-object/variable-contains-reference@2x.png b/1-js/04-object-basics/01-object/variable-contains-reference@2x.png similarity index 100% rename from 1-js/4-object-basics/01-object/variable-contains-reference@2x.png rename to 1-js/04-object-basics/01-object/variable-contains-reference@2x.png diff --git a/1-js/4-object-basics/01-object/variable-copy-reference.png b/1-js/04-object-basics/01-object/variable-copy-reference.png similarity index 100% rename from 1-js/4-object-basics/01-object/variable-copy-reference.png rename to 1-js/04-object-basics/01-object/variable-copy-reference.png diff --git a/1-js/4-object-basics/01-object/variable-copy-reference@2x.png b/1-js/04-object-basics/01-object/variable-copy-reference@2x.png similarity index 100% rename from 1-js/4-object-basics/01-object/variable-copy-reference@2x.png rename to 1-js/04-object-basics/01-object/variable-copy-reference@2x.png diff --git a/1-js/4-object-basics/01-object/variable-copy-value.png b/1-js/04-object-basics/01-object/variable-copy-value.png similarity index 100% rename from 1-js/4-object-basics/01-object/variable-copy-value.png rename to 1-js/04-object-basics/01-object/variable-copy-value.png diff --git a/1-js/4-object-basics/01-object/variable-copy-value@2x.png b/1-js/04-object-basics/01-object/variable-copy-value@2x.png similarity index 100% rename from 1-js/4-object-basics/01-object/variable-copy-value@2x.png rename to 1-js/04-object-basics/01-object/variable-copy-value@2x.png diff --git a/1-js/4-object-basics/02-garbage-collection/article.md b/1-js/04-object-basics/02-garbage-collection/article.md similarity index 100% rename from 1-js/4-object-basics/02-garbage-collection/article.md rename to 1-js/04-object-basics/02-garbage-collection/article.md diff --git a/1-js/4-object-basics/02-garbage-collection/family-delete-refs.png b/1-js/04-object-basics/02-garbage-collection/family-delete-refs.png similarity index 100% rename from 1-js/4-object-basics/02-garbage-collection/family-delete-refs.png rename to 1-js/04-object-basics/02-garbage-collection/family-delete-refs.png diff --git a/1-js/4-object-basics/02-garbage-collection/family-delete-refs@2x.png b/1-js/04-object-basics/02-garbage-collection/family-delete-refs@2x.png similarity index 100% rename from 1-js/4-object-basics/02-garbage-collection/family-delete-refs@2x.png rename to 1-js/04-object-basics/02-garbage-collection/family-delete-refs@2x.png diff --git a/1-js/4-object-basics/02-garbage-collection/family-no-family.png b/1-js/04-object-basics/02-garbage-collection/family-no-family.png similarity index 100% rename from 1-js/4-object-basics/02-garbage-collection/family-no-family.png rename to 1-js/04-object-basics/02-garbage-collection/family-no-family.png diff --git a/1-js/4-object-basics/02-garbage-collection/family-no-family@2x.png b/1-js/04-object-basics/02-garbage-collection/family-no-family@2x.png similarity index 100% rename from 1-js/4-object-basics/02-garbage-collection/family-no-family@2x.png rename to 1-js/04-object-basics/02-garbage-collection/family-no-family@2x.png diff --git a/1-js/4-object-basics/02-garbage-collection/family-no-father-2.png b/1-js/04-object-basics/02-garbage-collection/family-no-father-2.png similarity index 100% rename from 1-js/4-object-basics/02-garbage-collection/family-no-father-2.png rename to 1-js/04-object-basics/02-garbage-collection/family-no-father-2.png diff --git a/1-js/4-object-basics/02-garbage-collection/family-no-father-2@2x.png b/1-js/04-object-basics/02-garbage-collection/family-no-father-2@2x.png similarity index 100% rename from 1-js/4-object-basics/02-garbage-collection/family-no-father-2@2x.png rename to 1-js/04-object-basics/02-garbage-collection/family-no-father-2@2x.png diff --git a/1-js/4-object-basics/02-garbage-collection/family-no-father.png b/1-js/04-object-basics/02-garbage-collection/family-no-father.png similarity index 100% rename from 1-js/4-object-basics/02-garbage-collection/family-no-father.png rename to 1-js/04-object-basics/02-garbage-collection/family-no-father.png diff --git a/1-js/4-object-basics/02-garbage-collection/family-no-father@2x.png b/1-js/04-object-basics/02-garbage-collection/family-no-father@2x.png similarity index 100% rename from 1-js/4-object-basics/02-garbage-collection/family-no-father@2x.png rename to 1-js/04-object-basics/02-garbage-collection/family-no-father@2x.png diff --git a/1-js/4-object-basics/02-garbage-collection/family.png b/1-js/04-object-basics/02-garbage-collection/family.png similarity index 100% rename from 1-js/4-object-basics/02-garbage-collection/family.png rename to 1-js/04-object-basics/02-garbage-collection/family.png diff --git a/1-js/4-object-basics/02-garbage-collection/family@2x.png b/1-js/04-object-basics/02-garbage-collection/family@2x.png similarity index 100% rename from 1-js/4-object-basics/02-garbage-collection/family@2x.png rename to 1-js/04-object-basics/02-garbage-collection/family@2x.png diff --git a/1-js/4-object-basics/02-garbage-collection/garbage-collection-1.png b/1-js/04-object-basics/02-garbage-collection/garbage-collection-1.png similarity index 100% rename from 1-js/4-object-basics/02-garbage-collection/garbage-collection-1.png rename to 1-js/04-object-basics/02-garbage-collection/garbage-collection-1.png diff --git a/1-js/4-object-basics/02-garbage-collection/garbage-collection-1@2x.png b/1-js/04-object-basics/02-garbage-collection/garbage-collection-1@2x.png similarity index 100% rename from 1-js/4-object-basics/02-garbage-collection/garbage-collection-1@2x.png rename to 1-js/04-object-basics/02-garbage-collection/garbage-collection-1@2x.png diff --git a/1-js/4-object-basics/02-garbage-collection/garbage-collection-2.png b/1-js/04-object-basics/02-garbage-collection/garbage-collection-2.png similarity index 100% rename from 1-js/4-object-basics/02-garbage-collection/garbage-collection-2.png rename to 1-js/04-object-basics/02-garbage-collection/garbage-collection-2.png diff --git a/1-js/4-object-basics/02-garbage-collection/garbage-collection-2@2x.png b/1-js/04-object-basics/02-garbage-collection/garbage-collection-2@2x.png similarity index 100% rename from 1-js/4-object-basics/02-garbage-collection/garbage-collection-2@2x.png rename to 1-js/04-object-basics/02-garbage-collection/garbage-collection-2@2x.png diff --git a/1-js/4-object-basics/02-garbage-collection/garbage-collection-3.png b/1-js/04-object-basics/02-garbage-collection/garbage-collection-3.png similarity index 100% rename from 1-js/4-object-basics/02-garbage-collection/garbage-collection-3.png rename to 1-js/04-object-basics/02-garbage-collection/garbage-collection-3.png diff --git a/1-js/4-object-basics/02-garbage-collection/garbage-collection-3@2x.png b/1-js/04-object-basics/02-garbage-collection/garbage-collection-3@2x.png similarity index 100% rename from 1-js/4-object-basics/02-garbage-collection/garbage-collection-3@2x.png rename to 1-js/04-object-basics/02-garbage-collection/garbage-collection-3@2x.png diff --git a/1-js/4-object-basics/02-garbage-collection/garbage-collection-4.png b/1-js/04-object-basics/02-garbage-collection/garbage-collection-4.png similarity index 100% rename from 1-js/4-object-basics/02-garbage-collection/garbage-collection-4.png rename to 1-js/04-object-basics/02-garbage-collection/garbage-collection-4.png diff --git a/1-js/4-object-basics/02-garbage-collection/garbage-collection-4@2x.png b/1-js/04-object-basics/02-garbage-collection/garbage-collection-4@2x.png similarity index 100% rename from 1-js/4-object-basics/02-garbage-collection/garbage-collection-4@2x.png rename to 1-js/04-object-basics/02-garbage-collection/garbage-collection-4@2x.png diff --git a/1-js/4-object-basics/02-garbage-collection/garbage-collection-5.png b/1-js/04-object-basics/02-garbage-collection/garbage-collection-5.png similarity index 100% rename from 1-js/4-object-basics/02-garbage-collection/garbage-collection-5.png rename to 1-js/04-object-basics/02-garbage-collection/garbage-collection-5.png diff --git a/1-js/4-object-basics/02-garbage-collection/garbage-collection-5@2x.png b/1-js/04-object-basics/02-garbage-collection/garbage-collection-5@2x.png similarity index 100% rename from 1-js/4-object-basics/02-garbage-collection/garbage-collection-5@2x.png rename to 1-js/04-object-basics/02-garbage-collection/garbage-collection-5@2x.png diff --git a/1-js/4-object-basics/02-garbage-collection/garbage-collection.png b/1-js/04-object-basics/02-garbage-collection/garbage-collection.png similarity index 100% rename from 1-js/4-object-basics/02-garbage-collection/garbage-collection.png rename to 1-js/04-object-basics/02-garbage-collection/garbage-collection.png diff --git a/1-js/4-object-basics/02-garbage-collection/garbage-collection@2x.png b/1-js/04-object-basics/02-garbage-collection/garbage-collection@2x.png similarity index 100% rename from 1-js/4-object-basics/02-garbage-collection/garbage-collection@2x.png rename to 1-js/04-object-basics/02-garbage-collection/garbage-collection@2x.png diff --git a/1-js/4-object-basics/02-garbage-collection/memory-user-john-admin.png b/1-js/04-object-basics/02-garbage-collection/memory-user-john-admin.png similarity index 100% rename from 1-js/4-object-basics/02-garbage-collection/memory-user-john-admin.png rename to 1-js/04-object-basics/02-garbage-collection/memory-user-john-admin.png diff --git a/1-js/4-object-basics/02-garbage-collection/memory-user-john-admin@2x.png b/1-js/04-object-basics/02-garbage-collection/memory-user-john-admin@2x.png similarity index 100% rename from 1-js/4-object-basics/02-garbage-collection/memory-user-john-admin@2x.png rename to 1-js/04-object-basics/02-garbage-collection/memory-user-john-admin@2x.png diff --git a/1-js/4-object-basics/02-garbage-collection/memory-user-john-lost.png b/1-js/04-object-basics/02-garbage-collection/memory-user-john-lost.png similarity index 100% rename from 1-js/4-object-basics/02-garbage-collection/memory-user-john-lost.png rename to 1-js/04-object-basics/02-garbage-collection/memory-user-john-lost.png diff --git a/1-js/4-object-basics/02-garbage-collection/memory-user-john-lost@2x.png b/1-js/04-object-basics/02-garbage-collection/memory-user-john-lost@2x.png similarity index 100% rename from 1-js/4-object-basics/02-garbage-collection/memory-user-john-lost@2x.png rename to 1-js/04-object-basics/02-garbage-collection/memory-user-john-lost@2x.png diff --git a/1-js/4-object-basics/02-garbage-collection/memory-user-john.png b/1-js/04-object-basics/02-garbage-collection/memory-user-john.png similarity index 100% rename from 1-js/4-object-basics/02-garbage-collection/memory-user-john.png rename to 1-js/04-object-basics/02-garbage-collection/memory-user-john.png diff --git a/1-js/4-object-basics/02-garbage-collection/memory-user-john@2x.png b/1-js/04-object-basics/02-garbage-collection/memory-user-john@2x.png similarity index 100% rename from 1-js/4-object-basics/02-garbage-collection/memory-user-john@2x.png rename to 1-js/04-object-basics/02-garbage-collection/memory-user-john@2x.png diff --git a/1-js/4-object-basics/03-symbol/article.md b/1-js/04-object-basics/03-symbol/article.md similarity index 100% rename from 1-js/4-object-basics/03-symbol/article.md rename to 1-js/04-object-basics/03-symbol/article.md diff --git a/1-js/4-object-basics/04-object-methods/2-check-syntax/solution.md b/1-js/04-object-basics/04-object-methods/2-check-syntax/solution.md similarity index 100% rename from 1-js/4-object-basics/04-object-methods/2-check-syntax/solution.md rename to 1-js/04-object-basics/04-object-methods/2-check-syntax/solution.md diff --git a/1-js/4-object-basics/04-object-methods/2-check-syntax/task.md b/1-js/04-object-basics/04-object-methods/2-check-syntax/task.md similarity index 100% rename from 1-js/4-object-basics/04-object-methods/2-check-syntax/task.md rename to 1-js/04-object-basics/04-object-methods/2-check-syntax/task.md diff --git a/1-js/4-object-basics/04-object-methods/3-why-this/solution.md b/1-js/04-object-basics/04-object-methods/3-why-this/solution.md similarity index 100% rename from 1-js/4-object-basics/04-object-methods/3-why-this/solution.md rename to 1-js/04-object-basics/04-object-methods/3-why-this/solution.md diff --git a/1-js/4-object-basics/04-object-methods/3-why-this/task.md b/1-js/04-object-basics/04-object-methods/3-why-this/task.md similarity index 100% rename from 1-js/4-object-basics/04-object-methods/3-why-this/task.md rename to 1-js/04-object-basics/04-object-methods/3-why-this/task.md diff --git a/1-js/4-object-basics/04-object-methods/4-object-property-this/solution.md b/1-js/04-object-basics/04-object-methods/4-object-property-this/solution.md similarity index 100% rename from 1-js/4-object-basics/04-object-methods/4-object-property-this/solution.md rename to 1-js/04-object-basics/04-object-methods/4-object-property-this/solution.md diff --git a/1-js/4-object-basics/04-object-methods/4-object-property-this/task.md b/1-js/04-object-basics/04-object-methods/4-object-property-this/task.md similarity index 100% rename from 1-js/4-object-basics/04-object-methods/4-object-property-this/task.md rename to 1-js/04-object-basics/04-object-methods/4-object-property-this/task.md diff --git a/1-js/4-object-basics/04-object-methods/7-calculator/_js.view/solution.js b/1-js/04-object-basics/04-object-methods/7-calculator/_js.view/solution.js similarity index 100% rename from 1-js/4-object-basics/04-object-methods/7-calculator/_js.view/solution.js rename to 1-js/04-object-basics/04-object-methods/7-calculator/_js.view/solution.js diff --git a/1-js/4-object-basics/04-object-methods/7-calculator/_js.view/test.js b/1-js/04-object-basics/04-object-methods/7-calculator/_js.view/test.js similarity index 100% rename from 1-js/4-object-basics/04-object-methods/7-calculator/_js.view/test.js rename to 1-js/04-object-basics/04-object-methods/7-calculator/_js.view/test.js diff --git a/1-js/4-object-basics/04-object-methods/7-calculator/solution.md b/1-js/04-object-basics/04-object-methods/7-calculator/solution.md similarity index 100% rename from 1-js/4-object-basics/04-object-methods/7-calculator/solution.md rename to 1-js/04-object-basics/04-object-methods/7-calculator/solution.md diff --git a/1-js/4-object-basics/04-object-methods/7-calculator/task.md b/1-js/04-object-basics/04-object-methods/7-calculator/task.md similarity index 100% rename from 1-js/4-object-basics/04-object-methods/7-calculator/task.md rename to 1-js/04-object-basics/04-object-methods/7-calculator/task.md diff --git a/1-js/4-object-basics/04-object-methods/8-chain-calls/_js.view/solution.js b/1-js/04-object-basics/04-object-methods/8-chain-calls/_js.view/solution.js similarity index 100% rename from 1-js/4-object-basics/04-object-methods/8-chain-calls/_js.view/solution.js rename to 1-js/04-object-basics/04-object-methods/8-chain-calls/_js.view/solution.js diff --git a/1-js/4-object-basics/04-object-methods/8-chain-calls/_js.view/test.js b/1-js/04-object-basics/04-object-methods/8-chain-calls/_js.view/test.js similarity index 100% rename from 1-js/4-object-basics/04-object-methods/8-chain-calls/_js.view/test.js rename to 1-js/04-object-basics/04-object-methods/8-chain-calls/_js.view/test.js diff --git a/1-js/4-object-basics/04-object-methods/8-chain-calls/solution.md b/1-js/04-object-basics/04-object-methods/8-chain-calls/solution.md similarity index 100% rename from 1-js/4-object-basics/04-object-methods/8-chain-calls/solution.md rename to 1-js/04-object-basics/04-object-methods/8-chain-calls/solution.md diff --git a/1-js/4-object-basics/04-object-methods/8-chain-calls/task.md b/1-js/04-object-basics/04-object-methods/8-chain-calls/task.md similarity index 100% rename from 1-js/4-object-basics/04-object-methods/8-chain-calls/task.md rename to 1-js/04-object-basics/04-object-methods/8-chain-calls/task.md diff --git a/1-js/4-object-basics/04-object-methods/article.md b/1-js/04-object-basics/04-object-methods/article.md similarity index 100% rename from 1-js/4-object-basics/04-object-methods/article.md rename to 1-js/04-object-basics/04-object-methods/article.md diff --git a/1-js/4-object-basics/05-object-toprimitive/article.md b/1-js/04-object-basics/05-object-toprimitive/article.md similarity index 93% rename from 1-js/4-object-basics/05-object-toprimitive/article.md rename to 1-js/04-object-basics/05-object-toprimitive/article.md index 0741cc26..a1181bd2 100644 --- a/1-js/4-object-basics/05-object-toprimitive/article.md +++ b/1-js/04-object-basics/05-object-toprimitive/article.md @@ -71,11 +71,11 @@ There are 3 types (also called "hints") of object-to-primitive conversion: if (user == 1) { ... }; ``` - So, binary `+` and `==` use this hint. Seems right, because they operate both with strings and numbers. Although, there's some inconsistency here. The greater/less operator `<>` can work with both strings and numbers too. Still, it uses "number" hint. That's for historical reasons. + So, binary addition `+` and equality check `==` use this hint. Seems right, because they operate both with strings and numbers. Although, there's some inconsistency here. The greater/less operator `<>` can work with both strings and numbers too. Still, it uses "number" hint. That's for historical reasons. In practice, all built-in objects except for one case (`Date` object, we'll learn it later) implement `"default"` conversion the same way as `"number"`. And probably we should do the same. -Please note -- there are only three conversions. That simple. There is no "boolean" (all objects are `true` in boolean context) or anything else. And if we treat `"default"` and `"number"` the same, like most built-ins do, then there are only two conversions. +Please note -- there are only three conversions. That simple. There is no "boolean" hint (all objects are `true` in boolean context) or anything else. And if we treat `"default"` and `"number"` the same, like most built-ins do, then there are only two conversions. To do the conversion, Javascript tries to find and call three object methods: @@ -207,6 +207,7 @@ For instance: ## Summary + [todo describe article] diff --git a/1-js/4-object-basics/07-constructor-new/1-two-functions-one-object/solution.md b/1-js/04-object-basics/07-constructor-new/1-two-functions-one-object/solution.md similarity index 100% rename from 1-js/4-object-basics/07-constructor-new/1-two-functions-one-object/solution.md rename to 1-js/04-object-basics/07-constructor-new/1-two-functions-one-object/solution.md diff --git a/1-js/4-object-basics/07-constructor-new/1-two-functions-one-object/task.md b/1-js/04-object-basics/07-constructor-new/1-two-functions-one-object/task.md similarity index 100% rename from 1-js/4-object-basics/07-constructor-new/1-two-functions-one-object/task.md rename to 1-js/04-object-basics/07-constructor-new/1-two-functions-one-object/task.md diff --git a/1-js/4-object-basics/07-constructor-new/2-calculator-constructor/_js.view/solution.js b/1-js/04-object-basics/07-constructor-new/2-calculator-constructor/_js.view/solution.js similarity index 100% rename from 1-js/4-object-basics/07-constructor-new/2-calculator-constructor/_js.view/solution.js rename to 1-js/04-object-basics/07-constructor-new/2-calculator-constructor/_js.view/solution.js diff --git a/1-js/4-object-basics/07-constructor-new/2-calculator-constructor/_js.view/test.js b/1-js/04-object-basics/07-constructor-new/2-calculator-constructor/_js.view/test.js similarity index 100% rename from 1-js/4-object-basics/07-constructor-new/2-calculator-constructor/_js.view/test.js rename to 1-js/04-object-basics/07-constructor-new/2-calculator-constructor/_js.view/test.js diff --git a/1-js/4-object-basics/07-constructor-new/2-calculator-constructor/solution.md b/1-js/04-object-basics/07-constructor-new/2-calculator-constructor/solution.md similarity index 100% rename from 1-js/4-object-basics/07-constructor-new/2-calculator-constructor/solution.md rename to 1-js/04-object-basics/07-constructor-new/2-calculator-constructor/solution.md diff --git a/1-js/4-object-basics/07-constructor-new/2-calculator-constructor/task.md b/1-js/04-object-basics/07-constructor-new/2-calculator-constructor/task.md similarity index 100% rename from 1-js/4-object-basics/07-constructor-new/2-calculator-constructor/task.md rename to 1-js/04-object-basics/07-constructor-new/2-calculator-constructor/task.md diff --git a/1-js/4-object-basics/07-constructor-new/3-accumulator/_js.view/solution.js b/1-js/04-object-basics/07-constructor-new/3-accumulator/_js.view/solution.js similarity index 100% rename from 1-js/4-object-basics/07-constructor-new/3-accumulator/_js.view/solution.js rename to 1-js/04-object-basics/07-constructor-new/3-accumulator/_js.view/solution.js diff --git a/1-js/4-object-basics/07-constructor-new/3-accumulator/_js.view/test.js b/1-js/04-object-basics/07-constructor-new/3-accumulator/_js.view/test.js similarity index 100% rename from 1-js/4-object-basics/07-constructor-new/3-accumulator/_js.view/test.js rename to 1-js/04-object-basics/07-constructor-new/3-accumulator/_js.view/test.js diff --git a/1-js/4-object-basics/07-constructor-new/3-accumulator/solution.md b/1-js/04-object-basics/07-constructor-new/3-accumulator/solution.md similarity index 100% rename from 1-js/4-object-basics/07-constructor-new/3-accumulator/solution.md rename to 1-js/04-object-basics/07-constructor-new/3-accumulator/solution.md diff --git a/1-js/4-object-basics/07-constructor-new/3-accumulator/task.md b/1-js/04-object-basics/07-constructor-new/3-accumulator/task.md similarity index 100% rename from 1-js/4-object-basics/07-constructor-new/3-accumulator/task.md rename to 1-js/04-object-basics/07-constructor-new/3-accumulator/task.md diff --git a/1-js/4-object-basics/07-constructor-new/4-calculator-extendable/_js.view/solution.js b/1-js/04-object-basics/07-constructor-new/4-calculator-extendable/_js.view/solution.js similarity index 100% rename from 1-js/4-object-basics/07-constructor-new/4-calculator-extendable/_js.view/solution.js rename to 1-js/04-object-basics/07-constructor-new/4-calculator-extendable/_js.view/solution.js diff --git a/1-js/4-object-basics/07-constructor-new/4-calculator-extendable/_js.view/test.js b/1-js/04-object-basics/07-constructor-new/4-calculator-extendable/_js.view/test.js similarity index 100% rename from 1-js/4-object-basics/07-constructor-new/4-calculator-extendable/_js.view/test.js rename to 1-js/04-object-basics/07-constructor-new/4-calculator-extendable/_js.view/test.js diff --git a/1-js/4-object-basics/07-constructor-new/4-calculator-extendable/solution.md b/1-js/04-object-basics/07-constructor-new/4-calculator-extendable/solution.md similarity index 100% rename from 1-js/4-object-basics/07-constructor-new/4-calculator-extendable/solution.md rename to 1-js/04-object-basics/07-constructor-new/4-calculator-extendable/solution.md diff --git a/1-js/4-object-basics/07-constructor-new/4-calculator-extendable/task.md b/1-js/04-object-basics/07-constructor-new/4-calculator-extendable/task.md similarity index 100% rename from 1-js/4-object-basics/07-constructor-new/4-calculator-extendable/task.md rename to 1-js/04-object-basics/07-constructor-new/4-calculator-extendable/task.md diff --git a/1-js/4-object-basics/07-constructor-new/article.md b/1-js/04-object-basics/07-constructor-new/article.md similarity index 100% rename from 1-js/4-object-basics/07-constructor-new/article.md rename to 1-js/04-object-basics/07-constructor-new/article.md diff --git a/1-js/4-object-basics/index.md b/1-js/04-object-basics/index.md similarity index 100% rename from 1-js/4-object-basics/index.md rename to 1-js/04-object-basics/index.md diff --git a/1-js/5-data-types/01-primitives-methods/1-string-new-property/solution.md b/1-js/05-data-types/01-primitives-methods/1-string-new-property/solution.md similarity index 100% rename from 1-js/5-data-types/01-primitives-methods/1-string-new-property/solution.md rename to 1-js/05-data-types/01-primitives-methods/1-string-new-property/solution.md diff --git a/1-js/5-data-types/01-primitives-methods/1-string-new-property/task.md b/1-js/05-data-types/01-primitives-methods/1-string-new-property/task.md similarity index 100% rename from 1-js/5-data-types/01-primitives-methods/1-string-new-property/task.md rename to 1-js/05-data-types/01-primitives-methods/1-string-new-property/task.md diff --git a/1-js/5-data-types/01-primitives-methods/article.md b/1-js/05-data-types/01-primitives-methods/article.md similarity index 100% rename from 1-js/5-data-types/01-primitives-methods/article.md rename to 1-js/05-data-types/01-primitives-methods/article.md diff --git a/1-js/5-data-types/02-number/1-sum-interface/solution.md b/1-js/05-data-types/02-number/1-sum-interface/solution.md similarity index 100% rename from 1-js/5-data-types/02-number/1-sum-interface/solution.md rename to 1-js/05-data-types/02-number/1-sum-interface/solution.md diff --git a/1-js/5-data-types/02-number/1-sum-interface/task.md b/1-js/05-data-types/02-number/1-sum-interface/task.md similarity index 100% rename from 1-js/5-data-types/02-number/1-sum-interface/task.md rename to 1-js/05-data-types/02-number/1-sum-interface/task.md diff --git a/1-js/5-data-types/02-number/2-why-rounded-down/solution.md b/1-js/05-data-types/02-number/2-why-rounded-down/solution.md similarity index 100% rename from 1-js/5-data-types/02-number/2-why-rounded-down/solution.md rename to 1-js/05-data-types/02-number/2-why-rounded-down/solution.md diff --git a/1-js/5-data-types/02-number/2-why-rounded-down/task.md b/1-js/05-data-types/02-number/2-why-rounded-down/task.md similarity index 100% rename from 1-js/5-data-types/02-number/2-why-rounded-down/task.md rename to 1-js/05-data-types/02-number/2-why-rounded-down/task.md diff --git a/1-js/5-data-types/02-number/3-repeat-until-number/_js.view/solution.js b/1-js/05-data-types/02-number/3-repeat-until-number/_js.view/solution.js similarity index 100% rename from 1-js/5-data-types/02-number/3-repeat-until-number/_js.view/solution.js rename to 1-js/05-data-types/02-number/3-repeat-until-number/_js.view/solution.js diff --git a/1-js/5-data-types/02-number/3-repeat-until-number/_js.view/test.js b/1-js/05-data-types/02-number/3-repeat-until-number/_js.view/test.js similarity index 100% rename from 1-js/5-data-types/02-number/3-repeat-until-number/_js.view/test.js rename to 1-js/05-data-types/02-number/3-repeat-until-number/_js.view/test.js diff --git a/1-js/5-data-types/02-number/3-repeat-until-number/solution.md b/1-js/05-data-types/02-number/3-repeat-until-number/solution.md similarity index 100% rename from 1-js/5-data-types/02-number/3-repeat-until-number/solution.md rename to 1-js/05-data-types/02-number/3-repeat-until-number/solution.md diff --git a/1-js/5-data-types/02-number/3-repeat-until-number/task.md b/1-js/05-data-types/02-number/3-repeat-until-number/task.md similarity index 100% rename from 1-js/5-data-types/02-number/3-repeat-until-number/task.md rename to 1-js/05-data-types/02-number/3-repeat-until-number/task.md diff --git a/1-js/5-data-types/02-number/4-endless-loop-error/solution.md b/1-js/05-data-types/02-number/4-endless-loop-error/solution.md similarity index 100% rename from 1-js/5-data-types/02-number/4-endless-loop-error/solution.md rename to 1-js/05-data-types/02-number/4-endless-loop-error/solution.md diff --git a/1-js/5-data-types/02-number/4-endless-loop-error/task.md b/1-js/05-data-types/02-number/4-endless-loop-error/task.md similarity index 100% rename from 1-js/5-data-types/02-number/4-endless-loop-error/task.md rename to 1-js/05-data-types/02-number/4-endless-loop-error/task.md diff --git a/1-js/5-data-types/02-number/8-random-min-max/solution.md b/1-js/05-data-types/02-number/8-random-min-max/solution.md similarity index 100% rename from 1-js/5-data-types/02-number/8-random-min-max/solution.md rename to 1-js/05-data-types/02-number/8-random-min-max/solution.md diff --git a/1-js/5-data-types/02-number/8-random-min-max/task.md b/1-js/05-data-types/02-number/8-random-min-max/task.md similarity index 100% rename from 1-js/5-data-types/02-number/8-random-min-max/task.md rename to 1-js/05-data-types/02-number/8-random-min-max/task.md diff --git a/1-js/5-data-types/02-number/9-random-int-min-max/solution.md b/1-js/05-data-types/02-number/9-random-int-min-max/solution.md similarity index 100% rename from 1-js/5-data-types/02-number/9-random-int-min-max/solution.md rename to 1-js/05-data-types/02-number/9-random-int-min-max/solution.md diff --git a/1-js/5-data-types/02-number/9-random-int-min-max/task.md b/1-js/05-data-types/02-number/9-random-int-min-max/task.md similarity index 100% rename from 1-js/5-data-types/02-number/9-random-int-min-max/task.md rename to 1-js/05-data-types/02-number/9-random-int-min-max/task.md diff --git a/1-js/5-data-types/02-number/article.md b/1-js/05-data-types/02-number/article.md similarity index 100% rename from 1-js/5-data-types/02-number/article.md rename to 1-js/05-data-types/02-number/article.md diff --git a/1-js/5-data-types/03-string/1-ucfirst/_js.view/solution.js b/1-js/05-data-types/03-string/1-ucfirst/_js.view/solution.js similarity index 100% rename from 1-js/5-data-types/03-string/1-ucfirst/_js.view/solution.js rename to 1-js/05-data-types/03-string/1-ucfirst/_js.view/solution.js diff --git a/1-js/5-data-types/03-string/1-ucfirst/_js.view/test.js b/1-js/05-data-types/03-string/1-ucfirst/_js.view/test.js similarity index 100% rename from 1-js/5-data-types/03-string/1-ucfirst/_js.view/test.js rename to 1-js/05-data-types/03-string/1-ucfirst/_js.view/test.js diff --git a/1-js/5-data-types/03-string/1-ucfirst/solution.md b/1-js/05-data-types/03-string/1-ucfirst/solution.md similarity index 100% rename from 1-js/5-data-types/03-string/1-ucfirst/solution.md rename to 1-js/05-data-types/03-string/1-ucfirst/solution.md diff --git a/1-js/5-data-types/03-string/1-ucfirst/task.md b/1-js/05-data-types/03-string/1-ucfirst/task.md similarity index 100% rename from 1-js/5-data-types/03-string/1-ucfirst/task.md rename to 1-js/05-data-types/03-string/1-ucfirst/task.md diff --git a/1-js/5-data-types/03-string/2-check-spam/_js.view/solution.js b/1-js/05-data-types/03-string/2-check-spam/_js.view/solution.js similarity index 100% rename from 1-js/5-data-types/03-string/2-check-spam/_js.view/solution.js rename to 1-js/05-data-types/03-string/2-check-spam/_js.view/solution.js diff --git a/1-js/5-data-types/03-string/2-check-spam/_js.view/test.js b/1-js/05-data-types/03-string/2-check-spam/_js.view/test.js similarity index 100% rename from 1-js/5-data-types/03-string/2-check-spam/_js.view/test.js rename to 1-js/05-data-types/03-string/2-check-spam/_js.view/test.js diff --git a/1-js/5-data-types/03-string/2-check-spam/solution.md b/1-js/05-data-types/03-string/2-check-spam/solution.md similarity index 100% rename from 1-js/5-data-types/03-string/2-check-spam/solution.md rename to 1-js/05-data-types/03-string/2-check-spam/solution.md diff --git a/1-js/5-data-types/03-string/2-check-spam/task.md b/1-js/05-data-types/03-string/2-check-spam/task.md similarity index 100% rename from 1-js/5-data-types/03-string/2-check-spam/task.md rename to 1-js/05-data-types/03-string/2-check-spam/task.md diff --git a/1-js/5-data-types/03-string/3-truncate/_js.view/solution.js b/1-js/05-data-types/03-string/3-truncate/_js.view/solution.js similarity index 100% rename from 1-js/5-data-types/03-string/3-truncate/_js.view/solution.js rename to 1-js/05-data-types/03-string/3-truncate/_js.view/solution.js diff --git a/1-js/5-data-types/03-string/3-truncate/_js.view/test.js b/1-js/05-data-types/03-string/3-truncate/_js.view/test.js similarity index 100% rename from 1-js/5-data-types/03-string/3-truncate/_js.view/test.js rename to 1-js/05-data-types/03-string/3-truncate/_js.view/test.js diff --git a/1-js/5-data-types/03-string/3-truncate/solution.md b/1-js/05-data-types/03-string/3-truncate/solution.md similarity index 100% rename from 1-js/5-data-types/03-string/3-truncate/solution.md rename to 1-js/05-data-types/03-string/3-truncate/solution.md diff --git a/1-js/5-data-types/03-string/3-truncate/task.md b/1-js/05-data-types/03-string/3-truncate/task.md similarity index 100% rename from 1-js/5-data-types/03-string/3-truncate/task.md rename to 1-js/05-data-types/03-string/3-truncate/task.md diff --git a/1-js/5-data-types/03-string/4-extract-currency/_js.view/solution.js b/1-js/05-data-types/03-string/4-extract-currency/_js.view/solution.js similarity index 100% rename from 1-js/5-data-types/03-string/4-extract-currency/_js.view/solution.js rename to 1-js/05-data-types/03-string/4-extract-currency/_js.view/solution.js diff --git a/1-js/5-data-types/03-string/4-extract-currency/_js.view/test.js b/1-js/05-data-types/03-string/4-extract-currency/_js.view/test.js similarity index 100% rename from 1-js/5-data-types/03-string/4-extract-currency/_js.view/test.js rename to 1-js/05-data-types/03-string/4-extract-currency/_js.view/test.js diff --git a/1-js/5-data-types/03-string/4-extract-currency/solution.md b/1-js/05-data-types/03-string/4-extract-currency/solution.md similarity index 100% rename from 1-js/5-data-types/03-string/4-extract-currency/solution.md rename to 1-js/05-data-types/03-string/4-extract-currency/solution.md diff --git a/1-js/5-data-types/03-string/4-extract-currency/task.md b/1-js/05-data-types/03-string/4-extract-currency/task.md similarity index 100% rename from 1-js/5-data-types/03-string/4-extract-currency/task.md rename to 1-js/05-data-types/03-string/4-extract-currency/task.md diff --git a/1-js/5-data-types/03-string/article.md b/1-js/05-data-types/03-string/article.md similarity index 100% rename from 1-js/5-data-types/03-string/article.md rename to 1-js/05-data-types/03-string/article.md diff --git a/1-js/5-data-types/04-array/1-item-value/solution.md b/1-js/05-data-types/04-array/1-item-value/solution.md similarity index 100% rename from 1-js/5-data-types/04-array/1-item-value/solution.md rename to 1-js/05-data-types/04-array/1-item-value/solution.md diff --git a/1-js/5-data-types/04-array/1-item-value/task.md b/1-js/05-data-types/04-array/1-item-value/task.md similarity index 100% rename from 1-js/5-data-types/04-array/1-item-value/task.md rename to 1-js/05-data-types/04-array/1-item-value/task.md diff --git a/1-js/5-data-types/04-array/10-maximal-subarray/_js.view/solution.js b/1-js/05-data-types/04-array/10-maximal-subarray/_js.view/solution.js similarity index 100% rename from 1-js/5-data-types/04-array/10-maximal-subarray/_js.view/solution.js rename to 1-js/05-data-types/04-array/10-maximal-subarray/_js.view/solution.js diff --git a/1-js/5-data-types/04-array/10-maximal-subarray/_js.view/test.js b/1-js/05-data-types/04-array/10-maximal-subarray/_js.view/test.js similarity index 100% rename from 1-js/5-data-types/04-array/10-maximal-subarray/_js.view/test.js rename to 1-js/05-data-types/04-array/10-maximal-subarray/_js.view/test.js diff --git a/1-js/5-data-types/04-array/10-maximal-subarray/solution.md b/1-js/05-data-types/04-array/10-maximal-subarray/solution.md similarity index 100% rename from 1-js/5-data-types/04-array/10-maximal-subarray/solution.md rename to 1-js/05-data-types/04-array/10-maximal-subarray/solution.md diff --git a/1-js/5-data-types/04-array/10-maximal-subarray/task.md b/1-js/05-data-types/04-array/10-maximal-subarray/task.md similarity index 100% rename from 1-js/5-data-types/04-array/10-maximal-subarray/task.md rename to 1-js/05-data-types/04-array/10-maximal-subarray/task.md diff --git a/1-js/5-data-types/04-array/2-create-array/solution.md b/1-js/05-data-types/04-array/2-create-array/solution.md similarity index 100% rename from 1-js/5-data-types/04-array/2-create-array/solution.md rename to 1-js/05-data-types/04-array/2-create-array/solution.md diff --git a/1-js/5-data-types/04-array/2-create-array/task.md b/1-js/05-data-types/04-array/2-create-array/task.md similarity index 100% rename from 1-js/5-data-types/04-array/2-create-array/task.md rename to 1-js/05-data-types/04-array/2-create-array/task.md diff --git a/1-js/5-data-types/04-array/3-call-array-this/solution.md b/1-js/05-data-types/04-array/3-call-array-this/solution.md similarity index 100% rename from 1-js/5-data-types/04-array/3-call-array-this/solution.md rename to 1-js/05-data-types/04-array/3-call-array-this/solution.md diff --git a/1-js/5-data-types/04-array/3-call-array-this/task.md b/1-js/05-data-types/04-array/3-call-array-this/task.md similarity index 100% rename from 1-js/5-data-types/04-array/3-call-array-this/task.md rename to 1-js/05-data-types/04-array/3-call-array-this/task.md diff --git a/1-js/5-data-types/04-array/5-array-input-sum/solution.md b/1-js/05-data-types/04-array/5-array-input-sum/solution.md similarity index 100% rename from 1-js/5-data-types/04-array/5-array-input-sum/solution.md rename to 1-js/05-data-types/04-array/5-array-input-sum/solution.md diff --git a/1-js/5-data-types/04-array/5-array-input-sum/task.md b/1-js/05-data-types/04-array/5-array-input-sum/task.md similarity index 100% rename from 1-js/5-data-types/04-array/5-array-input-sum/task.md rename to 1-js/05-data-types/04-array/5-array-input-sum/task.md diff --git a/1-js/5-data-types/04-array/array-pop.png b/1-js/05-data-types/04-array/array-pop.png similarity index 100% rename from 1-js/5-data-types/04-array/array-pop.png rename to 1-js/05-data-types/04-array/array-pop.png diff --git a/1-js/5-data-types/04-array/array-pop@2x.png b/1-js/05-data-types/04-array/array-pop@2x.png similarity index 100% rename from 1-js/5-data-types/04-array/array-pop@2x.png rename to 1-js/05-data-types/04-array/array-pop@2x.png diff --git a/1-js/5-data-types/04-array/array-shift.png b/1-js/05-data-types/04-array/array-shift.png similarity index 100% rename from 1-js/5-data-types/04-array/array-shift.png rename to 1-js/05-data-types/04-array/array-shift.png diff --git a/1-js/5-data-types/04-array/array-shift@2x.png b/1-js/05-data-types/04-array/array-shift@2x.png similarity index 100% rename from 1-js/5-data-types/04-array/array-shift@2x.png rename to 1-js/05-data-types/04-array/array-shift@2x.png diff --git a/1-js/5-data-types/04-array/array-speed.png b/1-js/05-data-types/04-array/array-speed.png similarity index 100% rename from 1-js/5-data-types/04-array/array-speed.png rename to 1-js/05-data-types/04-array/array-speed.png diff --git a/1-js/5-data-types/04-array/array-speed@2x.png b/1-js/05-data-types/04-array/array-speed@2x.png similarity index 100% rename from 1-js/5-data-types/04-array/array-speed@2x.png rename to 1-js/05-data-types/04-array/array-speed@2x.png diff --git a/1-js/5-data-types/04-array/article.md b/1-js/05-data-types/04-array/article.md similarity index 100% rename from 1-js/5-data-types/04-array/article.md rename to 1-js/05-data-types/04-array/article.md diff --git a/1-js/5-data-types/04-array/queue.png b/1-js/05-data-types/04-array/queue.png similarity index 100% rename from 1-js/5-data-types/04-array/queue.png rename to 1-js/05-data-types/04-array/queue.png diff --git a/1-js/5-data-types/04-array/queue@2x.png b/1-js/05-data-types/04-array/queue@2x.png similarity index 100% rename from 1-js/5-data-types/04-array/queue@2x.png rename to 1-js/05-data-types/04-array/queue@2x.png diff --git a/1-js/5-data-types/04-array/stack.png b/1-js/05-data-types/04-array/stack.png similarity index 100% rename from 1-js/5-data-types/04-array/stack.png rename to 1-js/05-data-types/04-array/stack.png diff --git a/1-js/5-data-types/04-array/stack@2x.png b/1-js/05-data-types/04-array/stack@2x.png similarity index 100% rename from 1-js/5-data-types/04-array/stack@2x.png rename to 1-js/05-data-types/04-array/stack@2x.png diff --git a/1-js/5-data-types/05-array-methods/1-camelcase/_js.view/solution.js b/1-js/05-data-types/05-array-methods/1-camelcase/_js.view/solution.js similarity index 100% rename from 1-js/5-data-types/05-array-methods/1-camelcase/_js.view/solution.js rename to 1-js/05-data-types/05-array-methods/1-camelcase/_js.view/solution.js diff --git a/1-js/5-data-types/05-array-methods/1-camelcase/_js.view/test.js b/1-js/05-data-types/05-array-methods/1-camelcase/_js.view/test.js similarity index 100% rename from 1-js/5-data-types/05-array-methods/1-camelcase/_js.view/test.js rename to 1-js/05-data-types/05-array-methods/1-camelcase/_js.view/test.js diff --git a/1-js/5-data-types/05-array-methods/1-camelcase/solution.md b/1-js/05-data-types/05-array-methods/1-camelcase/solution.md similarity index 100% rename from 1-js/5-data-types/05-array-methods/1-camelcase/solution.md rename to 1-js/05-data-types/05-array-methods/1-camelcase/solution.md diff --git a/1-js/5-data-types/05-array-methods/1-camelcase/task.md b/1-js/05-data-types/05-array-methods/1-camelcase/task.md similarity index 100% rename from 1-js/5-data-types/05-array-methods/1-camelcase/task.md rename to 1-js/05-data-types/05-array-methods/1-camelcase/task.md diff --git a/1-js/5-data-types/05-array-methods/11-array-unique/_js.view/solution.js b/1-js/05-data-types/05-array-methods/11-array-unique/_js.view/solution.js similarity index 100% rename from 1-js/5-data-types/05-array-methods/11-array-unique/_js.view/solution.js rename to 1-js/05-data-types/05-array-methods/11-array-unique/_js.view/solution.js diff --git a/1-js/5-data-types/05-array-methods/11-array-unique/_js.view/test.js b/1-js/05-data-types/05-array-methods/11-array-unique/_js.view/test.js similarity index 100% rename from 1-js/5-data-types/05-array-methods/11-array-unique/_js.view/test.js rename to 1-js/05-data-types/05-array-methods/11-array-unique/_js.view/test.js diff --git a/1-js/5-data-types/05-array-methods/11-array-unique/solution.md b/1-js/05-data-types/05-array-methods/11-array-unique/solution.md similarity index 100% rename from 1-js/5-data-types/05-array-methods/11-array-unique/solution.md rename to 1-js/05-data-types/05-array-methods/11-array-unique/solution.md diff --git a/1-js/5-data-types/05-array-methods/11-array-unique/task.md b/1-js/05-data-types/05-array-methods/11-array-unique/task.md similarity index 100% rename from 1-js/5-data-types/05-array-methods/11-array-unique/task.md rename to 1-js/05-data-types/05-array-methods/11-array-unique/task.md diff --git a/1-js/5-data-types/05-array-methods/2-filter-range/_js.view/solution.js b/1-js/05-data-types/05-array-methods/2-filter-range/_js.view/solution.js similarity index 100% rename from 1-js/5-data-types/05-array-methods/2-filter-range/_js.view/solution.js rename to 1-js/05-data-types/05-array-methods/2-filter-range/_js.view/solution.js diff --git a/1-js/5-data-types/05-array-methods/2-filter-range/_js.view/test.js b/1-js/05-data-types/05-array-methods/2-filter-range/_js.view/test.js similarity index 100% rename from 1-js/5-data-types/05-array-methods/2-filter-range/_js.view/test.js rename to 1-js/05-data-types/05-array-methods/2-filter-range/_js.view/test.js diff --git a/1-js/5-data-types/05-array-methods/2-filter-range/solution.md b/1-js/05-data-types/05-array-methods/2-filter-range/solution.md similarity index 100% rename from 1-js/5-data-types/05-array-methods/2-filter-range/solution.md rename to 1-js/05-data-types/05-array-methods/2-filter-range/solution.md diff --git a/1-js/5-data-types/05-array-methods/2-filter-range/task.md b/1-js/05-data-types/05-array-methods/2-filter-range/task.md similarity index 100% rename from 1-js/5-data-types/05-array-methods/2-filter-range/task.md rename to 1-js/05-data-types/05-array-methods/2-filter-range/task.md diff --git a/1-js/5-data-types/05-array-methods/3-filter-range-in-place/_js.view/solution.js b/1-js/05-data-types/05-array-methods/3-filter-range-in-place/_js.view/solution.js similarity index 100% rename from 1-js/5-data-types/05-array-methods/3-filter-range-in-place/_js.view/solution.js rename to 1-js/05-data-types/05-array-methods/3-filter-range-in-place/_js.view/solution.js diff --git a/1-js/5-data-types/05-array-methods/3-filter-range-in-place/_js.view/test.js b/1-js/05-data-types/05-array-methods/3-filter-range-in-place/_js.view/test.js similarity index 100% rename from 1-js/5-data-types/05-array-methods/3-filter-range-in-place/_js.view/test.js rename to 1-js/05-data-types/05-array-methods/3-filter-range-in-place/_js.view/test.js diff --git a/1-js/5-data-types/05-array-methods/3-filter-range-in-place/solution.md b/1-js/05-data-types/05-array-methods/3-filter-range-in-place/solution.md similarity index 100% rename from 1-js/5-data-types/05-array-methods/3-filter-range-in-place/solution.md rename to 1-js/05-data-types/05-array-methods/3-filter-range-in-place/solution.md diff --git a/1-js/5-data-types/05-array-methods/3-filter-range-in-place/task.md b/1-js/05-data-types/05-array-methods/3-filter-range-in-place/task.md similarity index 100% rename from 1-js/5-data-types/05-array-methods/3-filter-range-in-place/task.md rename to 1-js/05-data-types/05-array-methods/3-filter-range-in-place/task.md diff --git a/1-js/5-data-types/05-array-methods/4-sort-back/solution.md b/1-js/05-data-types/05-array-methods/4-sort-back/solution.md similarity index 100% rename from 1-js/5-data-types/05-array-methods/4-sort-back/solution.md rename to 1-js/05-data-types/05-array-methods/4-sort-back/solution.md diff --git a/1-js/5-data-types/05-array-methods/4-sort-back/task.md b/1-js/05-data-types/05-array-methods/4-sort-back/task.md similarity index 100% rename from 1-js/5-data-types/05-array-methods/4-sort-back/task.md rename to 1-js/05-data-types/05-array-methods/4-sort-back/task.md diff --git a/1-js/5-data-types/05-array-methods/5-copy-sort-array/solution.md b/1-js/05-data-types/05-array-methods/5-copy-sort-array/solution.md similarity index 100% rename from 1-js/5-data-types/05-array-methods/5-copy-sort-array/solution.md rename to 1-js/05-data-types/05-array-methods/5-copy-sort-array/solution.md diff --git a/1-js/5-data-types/05-array-methods/5-copy-sort-array/task.md b/1-js/05-data-types/05-array-methods/5-copy-sort-array/task.md similarity index 100% rename from 1-js/5-data-types/05-array-methods/5-copy-sort-array/task.md rename to 1-js/05-data-types/05-array-methods/5-copy-sort-array/task.md diff --git a/1-js/5-data-types/05-array-methods/6-array-get-names/solution.md b/1-js/05-data-types/05-array-methods/6-array-get-names/solution.md similarity index 100% rename from 1-js/5-data-types/05-array-methods/6-array-get-names/solution.md rename to 1-js/05-data-types/05-array-methods/6-array-get-names/solution.md diff --git a/1-js/5-data-types/05-array-methods/6-array-get-names/task.md b/1-js/05-data-types/05-array-methods/6-array-get-names/task.md similarity index 100% rename from 1-js/5-data-types/05-array-methods/6-array-get-names/task.md rename to 1-js/05-data-types/05-array-methods/6-array-get-names/task.md diff --git a/1-js/5-data-types/05-array-methods/7-map-objects/solution.md b/1-js/05-data-types/05-array-methods/7-map-objects/solution.md similarity index 100% rename from 1-js/5-data-types/05-array-methods/7-map-objects/solution.md rename to 1-js/05-data-types/05-array-methods/7-map-objects/solution.md diff --git a/1-js/5-data-types/05-array-methods/7-map-objects/task.md b/1-js/05-data-types/05-array-methods/7-map-objects/task.md similarity index 100% rename from 1-js/5-data-types/05-array-methods/7-map-objects/task.md rename to 1-js/05-data-types/05-array-methods/7-map-objects/task.md diff --git a/1-js/5-data-types/05-array-methods/8-sort-objects/solution.md b/1-js/05-data-types/05-array-methods/8-sort-objects/solution.md similarity index 100% rename from 1-js/5-data-types/05-array-methods/8-sort-objects/solution.md rename to 1-js/05-data-types/05-array-methods/8-sort-objects/solution.md diff --git a/1-js/5-data-types/05-array-methods/8-sort-objects/task.md b/1-js/05-data-types/05-array-methods/8-sort-objects/task.md similarity index 100% rename from 1-js/5-data-types/05-array-methods/8-sort-objects/task.md rename to 1-js/05-data-types/05-array-methods/8-sort-objects/task.md diff --git a/1-js/5-data-types/05-array-methods/9-average-age/solution.md b/1-js/05-data-types/05-array-methods/9-average-age/solution.md similarity index 100% rename from 1-js/5-data-types/05-array-methods/9-average-age/solution.md rename to 1-js/05-data-types/05-array-methods/9-average-age/solution.md diff --git a/1-js/5-data-types/05-array-methods/9-average-age/task.md b/1-js/05-data-types/05-array-methods/9-average-age/task.md similarity index 100% rename from 1-js/5-data-types/05-array-methods/9-average-age/task.md rename to 1-js/05-data-types/05-array-methods/9-average-age/task.md diff --git a/1-js/5-data-types/05-array-methods/article.md b/1-js/05-data-types/05-array-methods/article.md similarity index 100% rename from 1-js/5-data-types/05-array-methods/article.md rename to 1-js/05-data-types/05-array-methods/article.md diff --git a/1-js/5-data-types/05-array-methods/reduce.png b/1-js/05-data-types/05-array-methods/reduce.png similarity index 100% rename from 1-js/5-data-types/05-array-methods/reduce.png rename to 1-js/05-data-types/05-array-methods/reduce.png diff --git a/1-js/5-data-types/05-array-methods/reduce@2x.png b/1-js/05-data-types/05-array-methods/reduce@2x.png similarity index 100% rename from 1-js/5-data-types/05-array-methods/reduce@2x.png rename to 1-js/05-data-types/05-array-methods/reduce@2x.png diff --git a/1-js/5-data-types/06-iterable/article.md b/1-js/05-data-types/06-iterable/article.md similarity index 100% rename from 1-js/5-data-types/06-iterable/article.md rename to 1-js/05-data-types/06-iterable/article.md diff --git a/1-js/5-data-types/07-map-set-weakmap-weakset/01-filter-anagrams/_js.view/solution.js b/1-js/05-data-types/07-map-set-weakmap-weakset/01-filter-anagrams/_js.view/solution.js similarity index 100% rename from 1-js/5-data-types/07-map-set-weakmap-weakset/01-filter-anagrams/_js.view/solution.js rename to 1-js/05-data-types/07-map-set-weakmap-weakset/01-filter-anagrams/_js.view/solution.js diff --git a/1-js/5-data-types/07-map-set-weakmap-weakset/01-filter-anagrams/_js.view/test.js b/1-js/05-data-types/07-map-set-weakmap-weakset/01-filter-anagrams/_js.view/test.js similarity index 100% rename from 1-js/5-data-types/07-map-set-weakmap-weakset/01-filter-anagrams/_js.view/test.js rename to 1-js/05-data-types/07-map-set-weakmap-weakset/01-filter-anagrams/_js.view/test.js diff --git a/1-js/5-data-types/07-map-set-weakmap-weakset/01-filter-anagrams/solution.md b/1-js/05-data-types/07-map-set-weakmap-weakset/01-filter-anagrams/solution.md similarity index 100% rename from 1-js/5-data-types/07-map-set-weakmap-weakset/01-filter-anagrams/solution.md rename to 1-js/05-data-types/07-map-set-weakmap-weakset/01-filter-anagrams/solution.md diff --git a/1-js/5-data-types/07-map-set-weakmap-weakset/01-filter-anagrams/task.md b/1-js/05-data-types/07-map-set-weakmap-weakset/01-filter-anagrams/task.md similarity index 100% rename from 1-js/5-data-types/07-map-set-weakmap-weakset/01-filter-anagrams/task.md rename to 1-js/05-data-types/07-map-set-weakmap-weakset/01-filter-anagrams/task.md diff --git a/1-js/5-data-types/07-map-set-weakmap-weakset/02-iterable-keys/solution.md b/1-js/05-data-types/07-map-set-weakmap-weakset/02-iterable-keys/solution.md similarity index 100% rename from 1-js/5-data-types/07-map-set-weakmap-weakset/02-iterable-keys/solution.md rename to 1-js/05-data-types/07-map-set-weakmap-weakset/02-iterable-keys/solution.md diff --git a/1-js/5-data-types/07-map-set-weakmap-weakset/02-iterable-keys/task.md b/1-js/05-data-types/07-map-set-weakmap-weakset/02-iterable-keys/task.md similarity index 100% rename from 1-js/5-data-types/07-map-set-weakmap-weakset/02-iterable-keys/task.md rename to 1-js/05-data-types/07-map-set-weakmap-weakset/02-iterable-keys/task.md diff --git a/1-js/5-data-types/07-map-set-weakmap-weakset/03-recipients-read/solution.md b/1-js/05-data-types/07-map-set-weakmap-weakset/03-recipients-read/solution.md similarity index 100% rename from 1-js/5-data-types/07-map-set-weakmap-weakset/03-recipients-read/solution.md rename to 1-js/05-data-types/07-map-set-weakmap-weakset/03-recipients-read/solution.md diff --git a/1-js/5-data-types/07-map-set-weakmap-weakset/03-recipients-read/task.md b/1-js/05-data-types/07-map-set-weakmap-weakset/03-recipients-read/task.md similarity index 100% rename from 1-js/5-data-types/07-map-set-weakmap-weakset/03-recipients-read/task.md rename to 1-js/05-data-types/07-map-set-weakmap-weakset/03-recipients-read/task.md diff --git a/1-js/5-data-types/07-map-set-weakmap-weakset/04-recipients-when-read/solution.md b/1-js/05-data-types/07-map-set-weakmap-weakset/04-recipients-when-read/solution.md similarity index 100% rename from 1-js/5-data-types/07-map-set-weakmap-weakset/04-recipients-when-read/solution.md rename to 1-js/05-data-types/07-map-set-weakmap-weakset/04-recipients-when-read/solution.md diff --git a/1-js/5-data-types/07-map-set-weakmap-weakset/04-recipients-when-read/task.md b/1-js/05-data-types/07-map-set-weakmap-weakset/04-recipients-when-read/task.md similarity index 100% rename from 1-js/5-data-types/07-map-set-weakmap-weakset/04-recipients-when-read/task.md rename to 1-js/05-data-types/07-map-set-weakmap-weakset/04-recipients-when-read/task.md diff --git a/1-js/5-data-types/07-map-set-weakmap-weakset/article.md b/1-js/05-data-types/07-map-set-weakmap-weakset/article.md similarity index 100% rename from 1-js/5-data-types/07-map-set-weakmap-weakset/article.md rename to 1-js/05-data-types/07-map-set-weakmap-weakset/article.md diff --git a/1-js/5-data-types/08-keys-values-entries/01-sum-salaries/_js.view/solution.js b/1-js/05-data-types/08-keys-values-entries/01-sum-salaries/_js.view/solution.js similarity index 100% rename from 1-js/5-data-types/08-keys-values-entries/01-sum-salaries/_js.view/solution.js rename to 1-js/05-data-types/08-keys-values-entries/01-sum-salaries/_js.view/solution.js diff --git a/1-js/5-data-types/08-keys-values-entries/01-sum-salaries/_js.view/test.js b/1-js/05-data-types/08-keys-values-entries/01-sum-salaries/_js.view/test.js similarity index 100% rename from 1-js/5-data-types/08-keys-values-entries/01-sum-salaries/_js.view/test.js rename to 1-js/05-data-types/08-keys-values-entries/01-sum-salaries/_js.view/test.js diff --git a/1-js/5-data-types/08-keys-values-entries/01-sum-salaries/solution.md b/1-js/05-data-types/08-keys-values-entries/01-sum-salaries/solution.md similarity index 100% rename from 1-js/5-data-types/08-keys-values-entries/01-sum-salaries/solution.md rename to 1-js/05-data-types/08-keys-values-entries/01-sum-salaries/solution.md diff --git a/1-js/5-data-types/08-keys-values-entries/01-sum-salaries/task.md b/1-js/05-data-types/08-keys-values-entries/01-sum-salaries/task.md similarity index 100% rename from 1-js/5-data-types/08-keys-values-entries/01-sum-salaries/task.md rename to 1-js/05-data-types/08-keys-values-entries/01-sum-salaries/task.md diff --git a/1-js/5-data-types/08-keys-values-entries/02-count-properties/_js.view/solution.js b/1-js/05-data-types/08-keys-values-entries/02-count-properties/_js.view/solution.js similarity index 100% rename from 1-js/5-data-types/08-keys-values-entries/02-count-properties/_js.view/solution.js rename to 1-js/05-data-types/08-keys-values-entries/02-count-properties/_js.view/solution.js diff --git a/1-js/5-data-types/08-keys-values-entries/02-count-properties/_js.view/test.js b/1-js/05-data-types/08-keys-values-entries/02-count-properties/_js.view/test.js similarity index 100% rename from 1-js/5-data-types/08-keys-values-entries/02-count-properties/_js.view/test.js rename to 1-js/05-data-types/08-keys-values-entries/02-count-properties/_js.view/test.js diff --git a/1-js/5-data-types/08-keys-values-entries/02-count-properties/solution.md b/1-js/05-data-types/08-keys-values-entries/02-count-properties/solution.md similarity index 100% rename from 1-js/5-data-types/08-keys-values-entries/02-count-properties/solution.md rename to 1-js/05-data-types/08-keys-values-entries/02-count-properties/solution.md diff --git a/1-js/5-data-types/08-keys-values-entries/02-count-properties/task.md b/1-js/05-data-types/08-keys-values-entries/02-count-properties/task.md similarity index 100% rename from 1-js/5-data-types/08-keys-values-entries/02-count-properties/task.md rename to 1-js/05-data-types/08-keys-values-entries/02-count-properties/task.md diff --git a/1-js/5-data-types/08-keys-values-entries/article.md b/1-js/05-data-types/08-keys-values-entries/article.md similarity index 100% rename from 1-js/5-data-types/08-keys-values-entries/article.md rename to 1-js/05-data-types/08-keys-values-entries/article.md diff --git a/1-js/5-data-types/09-destructuring-assignment/1-destructuring-assignment/solution.md b/1-js/05-data-types/09-destructuring-assignment/1-destructuring-assignment/solution.md similarity index 100% rename from 1-js/5-data-types/09-destructuring-assignment/1-destructuring-assignment/solution.md rename to 1-js/05-data-types/09-destructuring-assignment/1-destructuring-assignment/solution.md diff --git a/1-js/5-data-types/09-destructuring-assignment/1-destructuring-assignment/task.md b/1-js/05-data-types/09-destructuring-assignment/1-destructuring-assignment/task.md similarity index 100% rename from 1-js/5-data-types/09-destructuring-assignment/1-destructuring-assignment/task.md rename to 1-js/05-data-types/09-destructuring-assignment/1-destructuring-assignment/task.md diff --git a/1-js/5-data-types/09-destructuring-assignment/6-max-salary/_js.view/solution.js b/1-js/05-data-types/09-destructuring-assignment/6-max-salary/_js.view/solution.js similarity index 100% rename from 1-js/5-data-types/09-destructuring-assignment/6-max-salary/_js.view/solution.js rename to 1-js/05-data-types/09-destructuring-assignment/6-max-salary/_js.view/solution.js diff --git a/1-js/5-data-types/09-destructuring-assignment/6-max-salary/_js.view/test.js b/1-js/05-data-types/09-destructuring-assignment/6-max-salary/_js.view/test.js similarity index 100% rename from 1-js/5-data-types/09-destructuring-assignment/6-max-salary/_js.view/test.js rename to 1-js/05-data-types/09-destructuring-assignment/6-max-salary/_js.view/test.js diff --git a/1-js/5-data-types/09-destructuring-assignment/6-max-salary/solution.md b/1-js/05-data-types/09-destructuring-assignment/6-max-salary/solution.md similarity index 100% rename from 1-js/5-data-types/09-destructuring-assignment/6-max-salary/solution.md rename to 1-js/05-data-types/09-destructuring-assignment/6-max-salary/solution.md diff --git a/1-js/5-data-types/09-destructuring-assignment/6-max-salary/task.md b/1-js/05-data-types/09-destructuring-assignment/6-max-salary/task.md similarity index 100% rename from 1-js/5-data-types/09-destructuring-assignment/6-max-salary/task.md rename to 1-js/05-data-types/09-destructuring-assignment/6-max-salary/task.md diff --git a/1-js/5-data-types/09-destructuring-assignment/article.md b/1-js/05-data-types/09-destructuring-assignment/article.md similarity index 100% rename from 1-js/5-data-types/09-destructuring-assignment/article.md rename to 1-js/05-data-types/09-destructuring-assignment/article.md diff --git a/1-js/5-data-types/09-destructuring-assignment/destructuring-complex.png b/1-js/05-data-types/09-destructuring-assignment/destructuring-complex.png similarity index 100% rename from 1-js/5-data-types/09-destructuring-assignment/destructuring-complex.png rename to 1-js/05-data-types/09-destructuring-assignment/destructuring-complex.png diff --git a/1-js/5-data-types/09-destructuring-assignment/destructuring-complex@2x.png b/1-js/05-data-types/09-destructuring-assignment/destructuring-complex@2x.png similarity index 100% rename from 1-js/5-data-types/09-destructuring-assignment/destructuring-complex@2x.png rename to 1-js/05-data-types/09-destructuring-assignment/destructuring-complex@2x.png diff --git a/1-js/5-data-types/10-date/1-new-date/solution.md b/1-js/05-data-types/10-date/1-new-date/solution.md similarity index 100% rename from 1-js/5-data-types/10-date/1-new-date/solution.md rename to 1-js/05-data-types/10-date/1-new-date/solution.md diff --git a/1-js/5-data-types/10-date/1-new-date/task.md b/1-js/05-data-types/10-date/1-new-date/task.md similarity index 100% rename from 1-js/5-data-types/10-date/1-new-date/task.md rename to 1-js/05-data-types/10-date/1-new-date/task.md diff --git a/1-js/5-data-types/10-date/2-get-week-day/_js.view/solution.js b/1-js/05-data-types/10-date/2-get-week-day/_js.view/solution.js similarity index 100% rename from 1-js/5-data-types/10-date/2-get-week-day/_js.view/solution.js rename to 1-js/05-data-types/10-date/2-get-week-day/_js.view/solution.js diff --git a/1-js/5-data-types/10-date/2-get-week-day/_js.view/test.js b/1-js/05-data-types/10-date/2-get-week-day/_js.view/test.js similarity index 100% rename from 1-js/5-data-types/10-date/2-get-week-day/_js.view/test.js rename to 1-js/05-data-types/10-date/2-get-week-day/_js.view/test.js diff --git a/1-js/5-data-types/10-date/2-get-week-day/solution.md b/1-js/05-data-types/10-date/2-get-week-day/solution.md similarity index 100% rename from 1-js/5-data-types/10-date/2-get-week-day/solution.md rename to 1-js/05-data-types/10-date/2-get-week-day/solution.md diff --git a/1-js/5-data-types/10-date/2-get-week-day/task.md b/1-js/05-data-types/10-date/2-get-week-day/task.md similarity index 100% rename from 1-js/5-data-types/10-date/2-get-week-day/task.md rename to 1-js/05-data-types/10-date/2-get-week-day/task.md diff --git a/1-js/5-data-types/10-date/3-weekday/_js.view/solution.js b/1-js/05-data-types/10-date/3-weekday/_js.view/solution.js similarity index 100% rename from 1-js/5-data-types/10-date/3-weekday/_js.view/solution.js rename to 1-js/05-data-types/10-date/3-weekday/_js.view/solution.js diff --git a/1-js/5-data-types/10-date/3-weekday/_js.view/test.js b/1-js/05-data-types/10-date/3-weekday/_js.view/test.js similarity index 100% rename from 1-js/5-data-types/10-date/3-weekday/_js.view/test.js rename to 1-js/05-data-types/10-date/3-weekday/_js.view/test.js diff --git a/1-js/5-data-types/10-date/3-weekday/solution.md b/1-js/05-data-types/10-date/3-weekday/solution.md similarity index 100% rename from 1-js/5-data-types/10-date/3-weekday/solution.md rename to 1-js/05-data-types/10-date/3-weekday/solution.md diff --git a/1-js/5-data-types/10-date/3-weekday/task.md b/1-js/05-data-types/10-date/3-weekday/task.md similarity index 100% rename from 1-js/5-data-types/10-date/3-weekday/task.md rename to 1-js/05-data-types/10-date/3-weekday/task.md diff --git a/1-js/5-data-types/10-date/4-get-date-ago/_js.view/solution.js b/1-js/05-data-types/10-date/4-get-date-ago/_js.view/solution.js similarity index 100% rename from 1-js/5-data-types/10-date/4-get-date-ago/_js.view/solution.js rename to 1-js/05-data-types/10-date/4-get-date-ago/_js.view/solution.js diff --git a/1-js/5-data-types/10-date/4-get-date-ago/_js.view/test.js b/1-js/05-data-types/10-date/4-get-date-ago/_js.view/test.js similarity index 100% rename from 1-js/5-data-types/10-date/4-get-date-ago/_js.view/test.js rename to 1-js/05-data-types/10-date/4-get-date-ago/_js.view/test.js diff --git a/1-js/5-data-types/10-date/4-get-date-ago/solution.md b/1-js/05-data-types/10-date/4-get-date-ago/solution.md similarity index 100% rename from 1-js/5-data-types/10-date/4-get-date-ago/solution.md rename to 1-js/05-data-types/10-date/4-get-date-ago/solution.md diff --git a/1-js/5-data-types/10-date/4-get-date-ago/task.md b/1-js/05-data-types/10-date/4-get-date-ago/task.md similarity index 100% rename from 1-js/5-data-types/10-date/4-get-date-ago/task.md rename to 1-js/05-data-types/10-date/4-get-date-ago/task.md diff --git a/1-js/5-data-types/10-date/5-last-day-of-month/_js.view/solution.js b/1-js/05-data-types/10-date/5-last-day-of-month/_js.view/solution.js similarity index 100% rename from 1-js/5-data-types/10-date/5-last-day-of-month/_js.view/solution.js rename to 1-js/05-data-types/10-date/5-last-day-of-month/_js.view/solution.js diff --git a/1-js/5-data-types/10-date/5-last-day-of-month/_js.view/test.js b/1-js/05-data-types/10-date/5-last-day-of-month/_js.view/test.js similarity index 100% rename from 1-js/5-data-types/10-date/5-last-day-of-month/_js.view/test.js rename to 1-js/05-data-types/10-date/5-last-day-of-month/_js.view/test.js diff --git a/1-js/5-data-types/10-date/5-last-day-of-month/solution.md b/1-js/05-data-types/10-date/5-last-day-of-month/solution.md similarity index 100% rename from 1-js/5-data-types/10-date/5-last-day-of-month/solution.md rename to 1-js/05-data-types/10-date/5-last-day-of-month/solution.md diff --git a/1-js/5-data-types/10-date/5-last-day-of-month/task.md b/1-js/05-data-types/10-date/5-last-day-of-month/task.md similarity index 100% rename from 1-js/5-data-types/10-date/5-last-day-of-month/task.md rename to 1-js/05-data-types/10-date/5-last-day-of-month/task.md diff --git a/1-js/5-data-types/10-date/6-get-seconds-today/solution.md b/1-js/05-data-types/10-date/6-get-seconds-today/solution.md similarity index 100% rename from 1-js/5-data-types/10-date/6-get-seconds-today/solution.md rename to 1-js/05-data-types/10-date/6-get-seconds-today/solution.md diff --git a/1-js/5-data-types/10-date/6-get-seconds-today/task.md b/1-js/05-data-types/10-date/6-get-seconds-today/task.md similarity index 100% rename from 1-js/5-data-types/10-date/6-get-seconds-today/task.md rename to 1-js/05-data-types/10-date/6-get-seconds-today/task.md diff --git a/1-js/5-data-types/10-date/7-get-seconds-to-tomorrow/solution.md b/1-js/05-data-types/10-date/7-get-seconds-to-tomorrow/solution.md similarity index 100% rename from 1-js/5-data-types/10-date/7-get-seconds-to-tomorrow/solution.md rename to 1-js/05-data-types/10-date/7-get-seconds-to-tomorrow/solution.md diff --git a/1-js/5-data-types/10-date/7-get-seconds-to-tomorrow/task.md b/1-js/05-data-types/10-date/7-get-seconds-to-tomorrow/task.md similarity index 100% rename from 1-js/5-data-types/10-date/7-get-seconds-to-tomorrow/task.md rename to 1-js/05-data-types/10-date/7-get-seconds-to-tomorrow/task.md diff --git a/1-js/5-data-types/10-date/8-format-date-relative/_js.view/solution.js b/1-js/05-data-types/10-date/8-format-date-relative/_js.view/solution.js similarity index 100% rename from 1-js/5-data-types/10-date/8-format-date-relative/_js.view/solution.js rename to 1-js/05-data-types/10-date/8-format-date-relative/_js.view/solution.js diff --git a/1-js/5-data-types/10-date/8-format-date-relative/_js.view/test.js b/1-js/05-data-types/10-date/8-format-date-relative/_js.view/test.js similarity index 100% rename from 1-js/5-data-types/10-date/8-format-date-relative/_js.view/test.js rename to 1-js/05-data-types/10-date/8-format-date-relative/_js.view/test.js diff --git a/1-js/5-data-types/10-date/8-format-date-relative/solution.md b/1-js/05-data-types/10-date/8-format-date-relative/solution.md similarity index 100% rename from 1-js/5-data-types/10-date/8-format-date-relative/solution.md rename to 1-js/05-data-types/10-date/8-format-date-relative/solution.md diff --git a/1-js/5-data-types/10-date/8-format-date-relative/task.md b/1-js/05-data-types/10-date/8-format-date-relative/task.md similarity index 100% rename from 1-js/5-data-types/10-date/8-format-date-relative/task.md rename to 1-js/05-data-types/10-date/8-format-date-relative/task.md diff --git a/1-js/5-data-types/10-date/article.md b/1-js/05-data-types/10-date/article.md similarity index 100% rename from 1-js/5-data-types/10-date/article.md rename to 1-js/05-data-types/10-date/article.md diff --git a/1-js/5-data-types/11-json/1-serialize-object/solution.md b/1-js/05-data-types/11-json/1-serialize-object/solution.md similarity index 100% rename from 1-js/5-data-types/11-json/1-serialize-object/solution.md rename to 1-js/05-data-types/11-json/1-serialize-object/solution.md diff --git a/1-js/5-data-types/11-json/1-serialize-object/task.md b/1-js/05-data-types/11-json/1-serialize-object/task.md similarity index 100% rename from 1-js/5-data-types/11-json/1-serialize-object/task.md rename to 1-js/05-data-types/11-json/1-serialize-object/task.md diff --git a/1-js/5-data-types/11-json/2-serialize-event-circular/solution.md b/1-js/05-data-types/11-json/2-serialize-event-circular/solution.md similarity index 100% rename from 1-js/5-data-types/11-json/2-serialize-event-circular/solution.md rename to 1-js/05-data-types/11-json/2-serialize-event-circular/solution.md diff --git a/1-js/5-data-types/11-json/2-serialize-event-circular/task.md b/1-js/05-data-types/11-json/2-serialize-event-circular/task.md similarity index 100% rename from 1-js/5-data-types/11-json/2-serialize-event-circular/task.md rename to 1-js/05-data-types/11-json/2-serialize-event-circular/task.md diff --git a/1-js/5-data-types/11-json/article.md b/1-js/05-data-types/11-json/article.md similarity index 100% rename from 1-js/5-data-types/11-json/article.md rename to 1-js/05-data-types/11-json/article.md diff --git a/1-js/5-data-types/11-json/json-meetup.png b/1-js/05-data-types/11-json/json-meetup.png similarity index 100% rename from 1-js/5-data-types/11-json/json-meetup.png rename to 1-js/05-data-types/11-json/json-meetup.png diff --git a/1-js/5-data-types/11-json/json-meetup@2x.png b/1-js/05-data-types/11-json/json-meetup@2x.png similarity index 100% rename from 1-js/5-data-types/11-json/json-meetup@2x.png rename to 1-js/05-data-types/11-json/json-meetup@2x.png diff --git a/1-js/5-data-types/index.md b/1-js/05-data-types/index.md similarity index 100% rename from 1-js/5-data-types/index.md rename to 1-js/05-data-types/index.md diff --git a/1-js/8-more-functions/01-recursion/01-sum-to/solution.md b/1-js/06-more-functions/01-recursion/01-sum-to/solution.md similarity index 100% rename from 1-js/8-more-functions/01-recursion/01-sum-to/solution.md rename to 1-js/06-more-functions/01-recursion/01-sum-to/solution.md diff --git a/1-js/8-more-functions/01-recursion/01-sum-to/task.md b/1-js/06-more-functions/01-recursion/01-sum-to/task.md similarity index 100% rename from 1-js/8-more-functions/01-recursion/01-sum-to/task.md rename to 1-js/06-more-functions/01-recursion/01-sum-to/task.md diff --git a/1-js/8-more-functions/01-recursion/02-factorial/solution.md b/1-js/06-more-functions/01-recursion/02-factorial/solution.md similarity index 100% rename from 1-js/8-more-functions/01-recursion/02-factorial/solution.md rename to 1-js/06-more-functions/01-recursion/02-factorial/solution.md diff --git a/1-js/8-more-functions/01-recursion/02-factorial/task.md b/1-js/06-more-functions/01-recursion/02-factorial/task.md similarity index 100% rename from 1-js/8-more-functions/01-recursion/02-factorial/task.md rename to 1-js/06-more-functions/01-recursion/02-factorial/task.md diff --git a/1-js/8-more-functions/01-recursion/03-fibonacci-numbers/fibonacci-recursion-tree.png b/1-js/06-more-functions/01-recursion/03-fibonacci-numbers/fibonacci-recursion-tree.png similarity index 100% rename from 1-js/8-more-functions/01-recursion/03-fibonacci-numbers/fibonacci-recursion-tree.png rename to 1-js/06-more-functions/01-recursion/03-fibonacci-numbers/fibonacci-recursion-tree.png diff --git a/1-js/8-more-functions/01-recursion/03-fibonacci-numbers/fibonacci-recursion-tree@2x.png b/1-js/06-more-functions/01-recursion/03-fibonacci-numbers/fibonacci-recursion-tree@2x.png similarity index 100% rename from 1-js/8-more-functions/01-recursion/03-fibonacci-numbers/fibonacci-recursion-tree@2x.png rename to 1-js/06-more-functions/01-recursion/03-fibonacci-numbers/fibonacci-recursion-tree@2x.png diff --git a/1-js/8-more-functions/01-recursion/03-fibonacci-numbers/solution.md b/1-js/06-more-functions/01-recursion/03-fibonacci-numbers/solution.md similarity index 100% rename from 1-js/8-more-functions/01-recursion/03-fibonacci-numbers/solution.md rename to 1-js/06-more-functions/01-recursion/03-fibonacci-numbers/solution.md diff --git a/1-js/8-more-functions/01-recursion/03-fibonacci-numbers/task.md b/1-js/06-more-functions/01-recursion/03-fibonacci-numbers/task.md similarity index 100% rename from 1-js/8-more-functions/01-recursion/03-fibonacci-numbers/task.md rename to 1-js/06-more-functions/01-recursion/03-fibonacci-numbers/task.md diff --git a/1-js/8-more-functions/01-recursion/04-output-single-linked-list/solution.md b/1-js/06-more-functions/01-recursion/04-output-single-linked-list/solution.md similarity index 100% rename from 1-js/8-more-functions/01-recursion/04-output-single-linked-list/solution.md rename to 1-js/06-more-functions/01-recursion/04-output-single-linked-list/solution.md diff --git a/1-js/8-more-functions/01-recursion/04-output-single-linked-list/task.md b/1-js/06-more-functions/01-recursion/04-output-single-linked-list/task.md similarity index 100% rename from 1-js/8-more-functions/01-recursion/04-output-single-linked-list/task.md rename to 1-js/06-more-functions/01-recursion/04-output-single-linked-list/task.md diff --git a/1-js/8-more-functions/01-recursion/05-output-single-linked-list-reverse/solution.md b/1-js/06-more-functions/01-recursion/05-output-single-linked-list-reverse/solution.md similarity index 100% rename from 1-js/8-more-functions/01-recursion/05-output-single-linked-list-reverse/solution.md rename to 1-js/06-more-functions/01-recursion/05-output-single-linked-list-reverse/solution.md diff --git a/1-js/8-more-functions/01-recursion/05-output-single-linked-list-reverse/task.md b/1-js/06-more-functions/01-recursion/05-output-single-linked-list-reverse/task.md similarity index 100% rename from 1-js/8-more-functions/01-recursion/05-output-single-linked-list-reverse/task.md rename to 1-js/06-more-functions/01-recursion/05-output-single-linked-list-reverse/task.md diff --git a/1-js/8-more-functions/01-recursion/article.md b/1-js/06-more-functions/01-recursion/article.md similarity index 94% rename from 1-js/8-more-functions/01-recursion/article.md rename to 1-js/06-more-functions/01-recursion/article.md index 78f89e55..89568b07 100644 --- a/1-js/8-more-functions/01-recursion/article.md +++ b/1-js/06-more-functions/01-recursion/article.md @@ -514,13 +514,21 @@ Sometimes it's worth to add another variable named `tail` to track the last elem ## Summary -[todo better summary] +Terms: +- *Recursion* is a programming term that means a "self-calling" function. Such functions can be used to solve certain tasks in elegant ways. -Recursion -- is when a function calls itself, usually with other arguments. + When a function calls itself, that's called a *recursion step*. The *basis* of recursion is function arguments that make the task so simple that the function does not make further calls. -There are many applications of recursive calls: +- A [recursively-defined](https://en.wikipedia.org/wiki/Recursive_data_type) data structure is a data structure that can be defined using itself. -- Solving complex tasks by splitting into one or several simpler tasks. -- Dealing with [recursively-defined](https://en.wikipedia.org/wiki/Recursive_data_type) data structures, like HTML documents or trees. -- For "deep" cloning or inspection of complex objects. -- ...etc + For instance, the linked list can be defined as a data structure consisting of an object referencing a list (or null). + + ```js + list = { value, next -> list } + ``` + + Trees like HTML elements tree or the department tree from this chapter are also naturally recursive: they branch and every branch can have other branches. + + Recursive functions can be used to walk them as we've seen in the `sumSalary` example. + +Any recursive function can be rewritten into an iterative one. And that's sometimes required to optimize stuff. But for many tasks a recursive solution is fast enough and easier to write and support. diff --git a/1-js/8-more-functions/01-recursion/head.html b/1-js/06-more-functions/01-recursion/head.html similarity index 100% rename from 1-js/8-more-functions/01-recursion/head.html rename to 1-js/06-more-functions/01-recursion/head.html diff --git a/1-js/8-more-functions/01-recursion/linked-list-0.png b/1-js/06-more-functions/01-recursion/linked-list-0.png similarity index 100% rename from 1-js/8-more-functions/01-recursion/linked-list-0.png rename to 1-js/06-more-functions/01-recursion/linked-list-0.png diff --git a/1-js/8-more-functions/01-recursion/linked-list-0@2x.png b/1-js/06-more-functions/01-recursion/linked-list-0@2x.png similarity index 100% rename from 1-js/8-more-functions/01-recursion/linked-list-0@2x.png rename to 1-js/06-more-functions/01-recursion/linked-list-0@2x.png diff --git a/1-js/8-more-functions/01-recursion/linked-list-remove-1.png b/1-js/06-more-functions/01-recursion/linked-list-remove-1.png similarity index 100% rename from 1-js/8-more-functions/01-recursion/linked-list-remove-1.png rename to 1-js/06-more-functions/01-recursion/linked-list-remove-1.png diff --git a/1-js/8-more-functions/01-recursion/linked-list-remove-1@2x.png b/1-js/06-more-functions/01-recursion/linked-list-remove-1@2x.png similarity index 100% rename from 1-js/8-more-functions/01-recursion/linked-list-remove-1@2x.png rename to 1-js/06-more-functions/01-recursion/linked-list-remove-1@2x.png diff --git a/1-js/8-more-functions/01-recursion/linked-list-split.png b/1-js/06-more-functions/01-recursion/linked-list-split.png similarity index 100% rename from 1-js/8-more-functions/01-recursion/linked-list-split.png rename to 1-js/06-more-functions/01-recursion/linked-list-split.png diff --git a/1-js/8-more-functions/01-recursion/linked-list-split@2x.png b/1-js/06-more-functions/01-recursion/linked-list-split@2x.png similarity index 100% rename from 1-js/8-more-functions/01-recursion/linked-list-split@2x.png rename to 1-js/06-more-functions/01-recursion/linked-list-split@2x.png diff --git a/1-js/8-more-functions/01-recursion/linked-list.png b/1-js/06-more-functions/01-recursion/linked-list.png similarity index 100% rename from 1-js/8-more-functions/01-recursion/linked-list.png rename to 1-js/06-more-functions/01-recursion/linked-list.png diff --git a/1-js/8-more-functions/01-recursion/linked-list@2x.png b/1-js/06-more-functions/01-recursion/linked-list@2x.png similarity index 100% rename from 1-js/8-more-functions/01-recursion/linked-list@2x.png rename to 1-js/06-more-functions/01-recursion/linked-list@2x.png diff --git a/1-js/8-more-functions/01-recursion/recursion-pow.png b/1-js/06-more-functions/01-recursion/recursion-pow.png similarity index 100% rename from 1-js/8-more-functions/01-recursion/recursion-pow.png rename to 1-js/06-more-functions/01-recursion/recursion-pow.png diff --git a/1-js/8-more-functions/01-recursion/recursion-pow@2x.png b/1-js/06-more-functions/01-recursion/recursion-pow@2x.png similarity index 100% rename from 1-js/8-more-functions/01-recursion/recursion-pow@2x.png rename to 1-js/06-more-functions/01-recursion/recursion-pow@2x.png diff --git a/1-js/8-more-functions/01-recursion/recursive-salaries.png b/1-js/06-more-functions/01-recursion/recursive-salaries.png similarity index 100% rename from 1-js/8-more-functions/01-recursion/recursive-salaries.png rename to 1-js/06-more-functions/01-recursion/recursive-salaries.png diff --git a/1-js/8-more-functions/01-recursion/recursive-salaries@2x.png b/1-js/06-more-functions/01-recursion/recursive-salaries@2x.png similarity index 100% rename from 1-js/8-more-functions/01-recursion/recursive-salaries@2x.png rename to 1-js/06-more-functions/01-recursion/recursive-salaries@2x.png diff --git a/1-js/8-more-functions/02-rest-parameters-spread-operator/article.md b/1-js/06-more-functions/02-rest-parameters-spread-operator/article.md similarity index 100% rename from 1-js/8-more-functions/02-rest-parameters-spread-operator/article.md rename to 1-js/06-more-functions/02-rest-parameters-spread-operator/article.md diff --git a/1-js/8-more-functions/03-closure/1-counter-independent/solution.md b/1-js/06-more-functions/03-closure/1-counter-independent/solution.md similarity index 100% rename from 1-js/8-more-functions/03-closure/1-counter-independent/solution.md rename to 1-js/06-more-functions/03-closure/1-counter-independent/solution.md diff --git a/1-js/8-more-functions/03-closure/1-counter-independent/task.md b/1-js/06-more-functions/03-closure/1-counter-independent/task.md similarity index 100% rename from 1-js/8-more-functions/03-closure/1-counter-independent/task.md rename to 1-js/06-more-functions/03-closure/1-counter-independent/task.md diff --git a/1-js/8-more-functions/03-closure/2-counter-object-independent/solution.md b/1-js/06-more-functions/03-closure/2-counter-object-independent/solution.md similarity index 100% rename from 1-js/8-more-functions/03-closure/2-counter-object-independent/solution.md rename to 1-js/06-more-functions/03-closure/2-counter-object-independent/solution.md diff --git a/1-js/8-more-functions/03-closure/2-counter-object-independent/task.md b/1-js/06-more-functions/03-closure/2-counter-object-independent/task.md similarity index 100% rename from 1-js/8-more-functions/03-closure/2-counter-object-independent/task.md rename to 1-js/06-more-functions/03-closure/2-counter-object-independent/task.md diff --git a/1-js/8-more-functions/03-closure/3-function-in-if/solution.md b/1-js/06-more-functions/03-closure/3-function-in-if/solution.md similarity index 100% rename from 1-js/8-more-functions/03-closure/3-function-in-if/solution.md rename to 1-js/06-more-functions/03-closure/3-function-in-if/solution.md diff --git a/1-js/8-more-functions/03-closure/3-function-in-if/task.md b/1-js/06-more-functions/03-closure/3-function-in-if/task.md similarity index 100% rename from 1-js/8-more-functions/03-closure/3-function-in-if/task.md rename to 1-js/06-more-functions/03-closure/3-function-in-if/task.md diff --git a/1-js/8-more-functions/03-closure/4-closure-sum/solution.md b/1-js/06-more-functions/03-closure/4-closure-sum/solution.md similarity index 100% rename from 1-js/8-more-functions/03-closure/4-closure-sum/solution.md rename to 1-js/06-more-functions/03-closure/4-closure-sum/solution.md diff --git a/1-js/8-more-functions/03-closure/4-closure-sum/task.md b/1-js/06-more-functions/03-closure/4-closure-sum/task.md similarity index 100% rename from 1-js/8-more-functions/03-closure/4-closure-sum/task.md rename to 1-js/06-more-functions/03-closure/4-closure-sum/task.md diff --git a/1-js/8-more-functions/03-closure/6-filter-through-function/_js.view/solution.js b/1-js/06-more-functions/03-closure/6-filter-through-function/_js.view/solution.js similarity index 100% rename from 1-js/8-more-functions/03-closure/6-filter-through-function/_js.view/solution.js rename to 1-js/06-more-functions/03-closure/6-filter-through-function/_js.view/solution.js diff --git a/1-js/8-more-functions/03-closure/6-filter-through-function/_js.view/source.js b/1-js/06-more-functions/03-closure/6-filter-through-function/_js.view/source.js similarity index 100% rename from 1-js/8-more-functions/03-closure/6-filter-through-function/_js.view/source.js rename to 1-js/06-more-functions/03-closure/6-filter-through-function/_js.view/source.js diff --git a/1-js/8-more-functions/03-closure/6-filter-through-function/_js.view/test.js b/1-js/06-more-functions/03-closure/6-filter-through-function/_js.view/test.js similarity index 100% rename from 1-js/8-more-functions/03-closure/6-filter-through-function/_js.view/test.js rename to 1-js/06-more-functions/03-closure/6-filter-through-function/_js.view/test.js diff --git a/1-js/8-more-functions/03-closure/6-filter-through-function/solution.md b/1-js/06-more-functions/03-closure/6-filter-through-function/solution.md similarity index 100% rename from 1-js/8-more-functions/03-closure/6-filter-through-function/solution.md rename to 1-js/06-more-functions/03-closure/6-filter-through-function/solution.md diff --git a/1-js/8-more-functions/03-closure/6-filter-through-function/task.md b/1-js/06-more-functions/03-closure/6-filter-through-function/task.md similarity index 100% rename from 1-js/8-more-functions/03-closure/6-filter-through-function/task.md rename to 1-js/06-more-functions/03-closure/6-filter-through-function/task.md diff --git a/1-js/8-more-functions/03-closure/7-sort-by-field/solution.md b/1-js/06-more-functions/03-closure/7-sort-by-field/solution.md similarity index 100% rename from 1-js/8-more-functions/03-closure/7-sort-by-field/solution.md rename to 1-js/06-more-functions/03-closure/7-sort-by-field/solution.md diff --git a/1-js/8-more-functions/03-closure/7-sort-by-field/task.md b/1-js/06-more-functions/03-closure/7-sort-by-field/task.md similarity index 100% rename from 1-js/8-more-functions/03-closure/7-sort-by-field/task.md rename to 1-js/06-more-functions/03-closure/7-sort-by-field/task.md diff --git a/1-js/8-more-functions/03-closure/8-make-army/_js.view/solution.js b/1-js/06-more-functions/03-closure/8-make-army/_js.view/solution.js similarity index 100% rename from 1-js/8-more-functions/03-closure/8-make-army/_js.view/solution.js rename to 1-js/06-more-functions/03-closure/8-make-army/_js.view/solution.js diff --git a/1-js/8-more-functions/03-closure/8-make-army/_js.view/source.js b/1-js/06-more-functions/03-closure/8-make-army/_js.view/source.js similarity index 100% rename from 1-js/8-more-functions/03-closure/8-make-army/_js.view/source.js rename to 1-js/06-more-functions/03-closure/8-make-army/_js.view/source.js diff --git a/1-js/8-more-functions/03-closure/8-make-army/_js.view/test.js b/1-js/06-more-functions/03-closure/8-make-army/_js.view/test.js similarity index 100% rename from 1-js/8-more-functions/03-closure/8-make-army/_js.view/test.js rename to 1-js/06-more-functions/03-closure/8-make-army/_js.view/test.js diff --git a/1-js/8-more-functions/03-closure/8-make-army/lexenv-makearmy.png b/1-js/06-more-functions/03-closure/8-make-army/lexenv-makearmy.png similarity index 100% rename from 1-js/8-more-functions/03-closure/8-make-army/lexenv-makearmy.png rename to 1-js/06-more-functions/03-closure/8-make-army/lexenv-makearmy.png diff --git a/1-js/8-more-functions/03-closure/8-make-army/lexenv-makearmy@2x.png b/1-js/06-more-functions/03-closure/8-make-army/lexenv-makearmy@2x.png similarity index 100% rename from 1-js/8-more-functions/03-closure/8-make-army/lexenv-makearmy@2x.png rename to 1-js/06-more-functions/03-closure/8-make-army/lexenv-makearmy@2x.png diff --git a/1-js/8-more-functions/03-closure/8-make-army/solution.md b/1-js/06-more-functions/03-closure/8-make-army/solution.md similarity index 100% rename from 1-js/8-more-functions/03-closure/8-make-army/solution.md rename to 1-js/06-more-functions/03-closure/8-make-army/solution.md diff --git a/1-js/8-more-functions/03-closure/8-make-army/task.md b/1-js/06-more-functions/03-closure/8-make-army/task.md similarity index 100% rename from 1-js/8-more-functions/03-closure/8-make-army/task.md rename to 1-js/06-more-functions/03-closure/8-make-army/task.md diff --git a/1-js/8-more-functions/03-closure/article.md b/1-js/06-more-functions/03-closure/article.md similarity index 100% rename from 1-js/8-more-functions/03-closure/article.md rename to 1-js/06-more-functions/03-closure/article.md diff --git a/1-js/8-more-functions/03-closure/lexenv-if.png b/1-js/06-more-functions/03-closure/lexenv-if.png similarity index 100% rename from 1-js/8-more-functions/03-closure/lexenv-if.png rename to 1-js/06-more-functions/03-closure/lexenv-if.png diff --git a/1-js/8-more-functions/03-closure/lexenv-if@2x.png b/1-js/06-more-functions/03-closure/lexenv-if@2x.png similarity index 100% rename from 1-js/8-more-functions/03-closure/lexenv-if@2x.png rename to 1-js/06-more-functions/03-closure/lexenv-if@2x.png diff --git a/1-js/8-more-functions/03-closure/lexenv-nested-makecounter-1.png b/1-js/06-more-functions/03-closure/lexenv-nested-makecounter-1.png similarity index 100% rename from 1-js/8-more-functions/03-closure/lexenv-nested-makecounter-1.png rename to 1-js/06-more-functions/03-closure/lexenv-nested-makecounter-1.png diff --git a/1-js/8-more-functions/03-closure/lexenv-nested-makecounter-1@2x.png b/1-js/06-more-functions/03-closure/lexenv-nested-makecounter-1@2x.png similarity index 100% rename from 1-js/8-more-functions/03-closure/lexenv-nested-makecounter-1@2x.png rename to 1-js/06-more-functions/03-closure/lexenv-nested-makecounter-1@2x.png diff --git a/1-js/8-more-functions/03-closure/lexenv-nested-makecounter-2.png b/1-js/06-more-functions/03-closure/lexenv-nested-makecounter-2.png similarity index 100% rename from 1-js/8-more-functions/03-closure/lexenv-nested-makecounter-2.png rename to 1-js/06-more-functions/03-closure/lexenv-nested-makecounter-2.png diff --git a/1-js/8-more-functions/03-closure/lexenv-nested-makecounter-2@2x.png b/1-js/06-more-functions/03-closure/lexenv-nested-makecounter-2@2x.png similarity index 100% rename from 1-js/8-more-functions/03-closure/lexenv-nested-makecounter-2@2x.png rename to 1-js/06-more-functions/03-closure/lexenv-nested-makecounter-2@2x.png diff --git a/1-js/8-more-functions/03-closure/lexenv-nested-makecounter-3.png b/1-js/06-more-functions/03-closure/lexenv-nested-makecounter-3.png similarity index 100% rename from 1-js/8-more-functions/03-closure/lexenv-nested-makecounter-3.png rename to 1-js/06-more-functions/03-closure/lexenv-nested-makecounter-3.png diff --git a/1-js/8-more-functions/03-closure/lexenv-nested-makecounter-3@2x.png b/1-js/06-more-functions/03-closure/lexenv-nested-makecounter-3@2x.png similarity index 100% rename from 1-js/8-more-functions/03-closure/lexenv-nested-makecounter-3@2x.png rename to 1-js/06-more-functions/03-closure/lexenv-nested-makecounter-3@2x.png diff --git a/1-js/8-more-functions/03-closure/lexenv-nested-makecounter-4.png b/1-js/06-more-functions/03-closure/lexenv-nested-makecounter-4.png similarity index 100% rename from 1-js/8-more-functions/03-closure/lexenv-nested-makecounter-4.png rename to 1-js/06-more-functions/03-closure/lexenv-nested-makecounter-4.png diff --git a/1-js/8-more-functions/03-closure/lexenv-nested-makecounter-4@2x.png b/1-js/06-more-functions/03-closure/lexenv-nested-makecounter-4@2x.png similarity index 100% rename from 1-js/8-more-functions/03-closure/lexenv-nested-makecounter-4@2x.png rename to 1-js/06-more-functions/03-closure/lexenv-nested-makecounter-4@2x.png diff --git a/1-js/8-more-functions/03-closure/lexenv-nested-makecounter-5.png b/1-js/06-more-functions/03-closure/lexenv-nested-makecounter-5.png similarity index 100% rename from 1-js/8-more-functions/03-closure/lexenv-nested-makecounter-5.png rename to 1-js/06-more-functions/03-closure/lexenv-nested-makecounter-5.png diff --git a/1-js/8-more-functions/03-closure/lexenv-nested-makecounter-5@2x.png b/1-js/06-more-functions/03-closure/lexenv-nested-makecounter-5@2x.png similarity index 100% rename from 1-js/8-more-functions/03-closure/lexenv-nested-makecounter-5@2x.png rename to 1-js/06-more-functions/03-closure/lexenv-nested-makecounter-5@2x.png diff --git a/1-js/8-more-functions/03-closure/lexenv-nested-makecounter-6.png b/1-js/06-more-functions/03-closure/lexenv-nested-makecounter-6.png similarity index 100% rename from 1-js/8-more-functions/03-closure/lexenv-nested-makecounter-6.png rename to 1-js/06-more-functions/03-closure/lexenv-nested-makecounter-6.png diff --git a/1-js/8-more-functions/03-closure/lexenv-nested-makecounter-6@2x.png b/1-js/06-more-functions/03-closure/lexenv-nested-makecounter-6@2x.png similarity index 100% rename from 1-js/8-more-functions/03-closure/lexenv-nested-makecounter-6@2x.png rename to 1-js/06-more-functions/03-closure/lexenv-nested-makecounter-6@2x.png diff --git a/1-js/8-more-functions/03-closure/lexenv-nested-work.png b/1-js/06-more-functions/03-closure/lexenv-nested-work.png similarity index 100% rename from 1-js/8-more-functions/03-closure/lexenv-nested-work.png rename to 1-js/06-more-functions/03-closure/lexenv-nested-work.png diff --git a/1-js/8-more-functions/03-closure/lexenv-nested-work@2x.png b/1-js/06-more-functions/03-closure/lexenv-nested-work@2x.png similarity index 100% rename from 1-js/8-more-functions/03-closure/lexenv-nested-work@2x.png rename to 1-js/06-more-functions/03-closure/lexenv-nested-work@2x.png diff --git a/1-js/8-more-functions/03-closure/lexical-environment-global-2.png b/1-js/06-more-functions/03-closure/lexical-environment-global-2.png similarity index 100% rename from 1-js/8-more-functions/03-closure/lexical-environment-global-2.png rename to 1-js/06-more-functions/03-closure/lexical-environment-global-2.png diff --git a/1-js/8-more-functions/03-closure/lexical-environment-global-2@2x.png b/1-js/06-more-functions/03-closure/lexical-environment-global-2@2x.png similarity index 100% rename from 1-js/8-more-functions/03-closure/lexical-environment-global-2@2x.png rename to 1-js/06-more-functions/03-closure/lexical-environment-global-2@2x.png diff --git a/1-js/8-more-functions/03-closure/lexical-environment-global-3.png b/1-js/06-more-functions/03-closure/lexical-environment-global-3.png similarity index 100% rename from 1-js/8-more-functions/03-closure/lexical-environment-global-3.png rename to 1-js/06-more-functions/03-closure/lexical-environment-global-3.png diff --git a/1-js/8-more-functions/03-closure/lexical-environment-global-3@2x.png b/1-js/06-more-functions/03-closure/lexical-environment-global-3@2x.png similarity index 100% rename from 1-js/8-more-functions/03-closure/lexical-environment-global-3@2x.png rename to 1-js/06-more-functions/03-closure/lexical-environment-global-3@2x.png diff --git a/1-js/8-more-functions/03-closure/lexical-environment-global.png b/1-js/06-more-functions/03-closure/lexical-environment-global.png similarity index 100% rename from 1-js/8-more-functions/03-closure/lexical-environment-global.png rename to 1-js/06-more-functions/03-closure/lexical-environment-global.png diff --git a/1-js/8-more-functions/03-closure/lexical-environment-global@2x.png b/1-js/06-more-functions/03-closure/lexical-environment-global@2x.png similarity index 100% rename from 1-js/8-more-functions/03-closure/lexical-environment-global@2x.png rename to 1-js/06-more-functions/03-closure/lexical-environment-global@2x.png diff --git a/1-js/8-more-functions/03-closure/lexical-environment-simple-lookup.png b/1-js/06-more-functions/03-closure/lexical-environment-simple-lookup.png similarity index 100% rename from 1-js/8-more-functions/03-closure/lexical-environment-simple-lookup.png rename to 1-js/06-more-functions/03-closure/lexical-environment-simple-lookup.png diff --git a/1-js/8-more-functions/03-closure/lexical-environment-simple-lookup@2x.png b/1-js/06-more-functions/03-closure/lexical-environment-simple-lookup@2x.png similarity index 100% rename from 1-js/8-more-functions/03-closure/lexical-environment-simple-lookup@2x.png rename to 1-js/06-more-functions/03-closure/lexical-environment-simple-lookup@2x.png diff --git a/1-js/8-more-functions/03-closure/lexical-environment-simple.png b/1-js/06-more-functions/03-closure/lexical-environment-simple.png similarity index 100% rename from 1-js/8-more-functions/03-closure/lexical-environment-simple.png rename to 1-js/06-more-functions/03-closure/lexical-environment-simple.png diff --git a/1-js/8-more-functions/03-closure/lexical-environment-simple@2x.png b/1-js/06-more-functions/03-closure/lexical-environment-simple@2x.png similarity index 100% rename from 1-js/8-more-functions/03-closure/lexical-environment-simple@2x.png rename to 1-js/06-more-functions/03-closure/lexical-environment-simple@2x.png diff --git a/1-js/8-more-functions/03-closure/lexical-search-order.png b/1-js/06-more-functions/03-closure/lexical-search-order.png similarity index 100% rename from 1-js/8-more-functions/03-closure/lexical-search-order.png rename to 1-js/06-more-functions/03-closure/lexical-search-order.png diff --git a/1-js/8-more-functions/03-closure/lexical-search-order@2x.png b/1-js/06-more-functions/03-closure/lexical-search-order@2x.png similarity index 100% rename from 1-js/8-more-functions/03-closure/lexical-search-order@2x.png rename to 1-js/06-more-functions/03-closure/lexical-search-order@2x.png diff --git a/1-js/8-more-functions/04-global-object/article.md b/1-js/06-more-functions/04-global-object/article.md similarity index 100% rename from 1-js/8-more-functions/04-global-object/article.md rename to 1-js/06-more-functions/04-global-object/article.md diff --git a/1-js/8-more-functions/05-function-object/2-counter-inc-dec/_js.view/solution.js b/1-js/06-more-functions/05-function-object/2-counter-inc-dec/_js.view/solution.js similarity index 100% rename from 1-js/8-more-functions/05-function-object/2-counter-inc-dec/_js.view/solution.js rename to 1-js/06-more-functions/05-function-object/2-counter-inc-dec/_js.view/solution.js diff --git a/1-js/8-more-functions/05-function-object/2-counter-inc-dec/_js.view/source.js b/1-js/06-more-functions/05-function-object/2-counter-inc-dec/_js.view/source.js similarity index 100% rename from 1-js/8-more-functions/05-function-object/2-counter-inc-dec/_js.view/source.js rename to 1-js/06-more-functions/05-function-object/2-counter-inc-dec/_js.view/source.js diff --git a/1-js/8-more-functions/05-function-object/2-counter-inc-dec/_js.view/test.js b/1-js/06-more-functions/05-function-object/2-counter-inc-dec/_js.view/test.js similarity index 100% rename from 1-js/8-more-functions/05-function-object/2-counter-inc-dec/_js.view/test.js rename to 1-js/06-more-functions/05-function-object/2-counter-inc-dec/_js.view/test.js diff --git a/1-js/8-more-functions/05-function-object/2-counter-inc-dec/solution.md b/1-js/06-more-functions/05-function-object/2-counter-inc-dec/solution.md similarity index 100% rename from 1-js/8-more-functions/05-function-object/2-counter-inc-dec/solution.md rename to 1-js/06-more-functions/05-function-object/2-counter-inc-dec/solution.md diff --git a/1-js/8-more-functions/05-function-object/2-counter-inc-dec/task.md b/1-js/06-more-functions/05-function-object/2-counter-inc-dec/task.md similarity index 100% rename from 1-js/8-more-functions/05-function-object/2-counter-inc-dec/task.md rename to 1-js/06-more-functions/05-function-object/2-counter-inc-dec/task.md diff --git a/1-js/8-more-functions/05-function-object/5-sum-many-brackets/solution.md b/1-js/06-more-functions/05-function-object/5-sum-many-brackets/solution.md similarity index 100% rename from 1-js/8-more-functions/05-function-object/5-sum-many-brackets/solution.md rename to 1-js/06-more-functions/05-function-object/5-sum-many-brackets/solution.md diff --git a/1-js/8-more-functions/05-function-object/5-sum-many-brackets/task.md b/1-js/06-more-functions/05-function-object/5-sum-many-brackets/task.md similarity index 100% rename from 1-js/8-more-functions/05-function-object/5-sum-many-brackets/task.md rename to 1-js/06-more-functions/05-function-object/5-sum-many-brackets/task.md diff --git a/1-js/8-more-functions/05-function-object/article.md b/1-js/06-more-functions/05-function-object/article.md similarity index 100% rename from 1-js/8-more-functions/05-function-object/article.md rename to 1-js/06-more-functions/05-function-object/article.md diff --git a/1-js/8-more-functions/06-new-function/article.md b/1-js/06-more-functions/06-new-function/article.md similarity index 100% rename from 1-js/8-more-functions/06-new-function/article.md rename to 1-js/06-more-functions/06-new-function/article.md diff --git a/1-js/8-more-functions/07-settimeout-setinterval/1-output-numbers-100ms/solution.md b/1-js/06-more-functions/07-settimeout-setinterval/1-output-numbers-100ms/solution.md similarity index 100% rename from 1-js/8-more-functions/07-settimeout-setinterval/1-output-numbers-100ms/solution.md rename to 1-js/06-more-functions/07-settimeout-setinterval/1-output-numbers-100ms/solution.md diff --git a/1-js/8-more-functions/07-settimeout-setinterval/1-output-numbers-100ms/task.md b/1-js/06-more-functions/07-settimeout-setinterval/1-output-numbers-100ms/task.md similarity index 100% rename from 1-js/8-more-functions/07-settimeout-setinterval/1-output-numbers-100ms/task.md rename to 1-js/06-more-functions/07-settimeout-setinterval/1-output-numbers-100ms/task.md diff --git a/1-js/8-more-functions/07-settimeout-setinterval/3-rewrite-settimeout/solution.md b/1-js/06-more-functions/07-settimeout-setinterval/3-rewrite-settimeout/solution.md similarity index 100% rename from 1-js/8-more-functions/07-settimeout-setinterval/3-rewrite-settimeout/solution.md rename to 1-js/06-more-functions/07-settimeout-setinterval/3-rewrite-settimeout/solution.md diff --git a/1-js/8-more-functions/07-settimeout-setinterval/3-rewrite-settimeout/task.md b/1-js/06-more-functions/07-settimeout-setinterval/3-rewrite-settimeout/task.md similarity index 100% rename from 1-js/8-more-functions/07-settimeout-setinterval/3-rewrite-settimeout/task.md rename to 1-js/06-more-functions/07-settimeout-setinterval/3-rewrite-settimeout/task.md diff --git a/1-js/8-more-functions/07-settimeout-setinterval/4-settimeout-result/solution.md b/1-js/06-more-functions/07-settimeout-setinterval/4-settimeout-result/solution.md similarity index 100% rename from 1-js/8-more-functions/07-settimeout-setinterval/4-settimeout-result/solution.md rename to 1-js/06-more-functions/07-settimeout-setinterval/4-settimeout-result/solution.md diff --git a/1-js/8-more-functions/07-settimeout-setinterval/4-settimeout-result/task.md b/1-js/06-more-functions/07-settimeout-setinterval/4-settimeout-result/task.md similarity index 100% rename from 1-js/8-more-functions/07-settimeout-setinterval/4-settimeout-result/task.md rename to 1-js/06-more-functions/07-settimeout-setinterval/4-settimeout-result/task.md diff --git a/1-js/8-more-functions/07-settimeout-setinterval/article.md b/1-js/06-more-functions/07-settimeout-setinterval/article.md similarity index 86% rename from 1-js/8-more-functions/07-settimeout-setinterval/article.md rename to 1-js/06-more-functions/07-settimeout-setinterval/article.md index 54bce6a5..3f977fb0 100644 --- a/1-js/8-more-functions/07-settimeout-setinterval/article.md +++ b/1-js/06-more-functions/07-settimeout-setinterval/article.md @@ -1,8 +1,8 @@ # Scheduling: setTimeout and setInterval -We may decide to execute a function not right now, but at a certain time later. That's called *scheduling*. +We may decide to execute a function not right now, but at a certain time later. That's called "scheduling a call". -There are two methods to schedule function execution: +There are two methods for it: - `setTimeout` allows to run a function once after the given interval of time. - `setInterval` allows to run of the function regularly with the given interval between the runs. @@ -351,12 +351,18 @@ First timers run immediately (just as written in the spec), and then the delay c For server-side Javascript, that limitation does not exist. Also, there are other ways to schedule an immediate asynchronous job. In Node.JS that's [process.nextTick](https://nodejs.org/api/process.html) and [setImmediate](https://nodejs.org/api/timers.html). ```` -## Summary [todo] +## Summary -- Методы `setInterval(func, delay)` и `setTimeout(func, delay)` позволяют запускать `func` регулярно/один раз через `delay` миллисекунд. -- Оба метода возвращают идентификатор таймера. Его используют для остановки выполнения вызовом `clearInterval/clearTimeout`. -- В случаях, когда нужно гарантировать задержку между регулярными вызовами или гибко её менять, вместо `setInterval` используют рекурсивный `setTimeout`. -- Минимальная задержка по стандарту составляет `4 мс`. Браузеры соблюдают этот стандарт, но некоторые другие среды для выполнения JS, например Node.JS, могут предоставить и меньше задержки. -- В реальности срабатывания таймера могут быть гораздо реже, чем назначено, например если процессор перегружен, вкладка находится в фоновом режиме, ноутбук работает от батареи или по какой-то иной причине. +- Methods `setInterval(func, delay, ...args)` и `setTimeout(func, delay, ...args)` allow to run the `func` regularly/once after `delay` milliseconds. +- To cancel execution, we should `clearInterval/clearTimeout` on the value returned by `setInterval/setTimeout`. +- Nested `setTimeout` calls give more flexible control over the execution than `setInterval`. They also can guarantee the minimal time *between* the execution. +- Zero-timeout is sometimes used to schedule the call "as soon as possible". -Браузерных особенностей почти нет, разве что вызов `setInterval(..., 0)` с нулевой задержкой в IE недопустим, нужно указывать `setInterval(..., 1)`. +Please note that these methods do not *guarantee* the accurate delay. We should not rely on that in the scheduled code. + +For example, the in-browser timer may slowdown for a lot of reasons: +- The CPU is overloaded. +- The browser tab is in the background mode. +- The visitor's laptop is on battery. + +All that may decrease the minimal timer resolution (the minimal delay) to 300ms or even 1000ms depending on the browser and settings. diff --git a/1-js/8-more-functions/07-settimeout-setinterval/setinterval-interval.png b/1-js/06-more-functions/07-settimeout-setinterval/setinterval-interval.png similarity index 100% rename from 1-js/8-more-functions/07-settimeout-setinterval/setinterval-interval.png rename to 1-js/06-more-functions/07-settimeout-setinterval/setinterval-interval.png diff --git a/1-js/8-more-functions/07-settimeout-setinterval/setinterval-interval@2x.png b/1-js/06-more-functions/07-settimeout-setinterval/setinterval-interval@2x.png similarity index 100% rename from 1-js/8-more-functions/07-settimeout-setinterval/setinterval-interval@2x.png rename to 1-js/06-more-functions/07-settimeout-setinterval/setinterval-interval@2x.png diff --git a/1-js/8-more-functions/07-settimeout-setinterval/settimeout-interval.png b/1-js/06-more-functions/07-settimeout-setinterval/settimeout-interval.png similarity index 100% rename from 1-js/8-more-functions/07-settimeout-setinterval/settimeout-interval.png rename to 1-js/06-more-functions/07-settimeout-setinterval/settimeout-interval.png diff --git a/1-js/8-more-functions/07-settimeout-setinterval/settimeout-interval@2x.png b/1-js/06-more-functions/07-settimeout-setinterval/settimeout-interval@2x.png similarity index 100% rename from 1-js/8-more-functions/07-settimeout-setinterval/settimeout-interval@2x.png rename to 1-js/06-more-functions/07-settimeout-setinterval/settimeout-interval@2x.png diff --git a/1-js/8-more-functions/08-call-apply-decorators/2-spy-decorator/_js.view/solution.js b/1-js/06-more-functions/08-call-apply-decorators/01-spy-decorator/_js.view/solution.js similarity index 100% rename from 1-js/8-more-functions/08-call-apply-decorators/2-spy-decorator/_js.view/solution.js rename to 1-js/06-more-functions/08-call-apply-decorators/01-spy-decorator/_js.view/solution.js diff --git a/1-js/8-more-functions/08-call-apply-decorators/2-spy-decorator/_js.view/source.js b/1-js/06-more-functions/08-call-apply-decorators/01-spy-decorator/_js.view/source.js similarity index 100% rename from 1-js/8-more-functions/08-call-apply-decorators/2-spy-decorator/_js.view/source.js rename to 1-js/06-more-functions/08-call-apply-decorators/01-spy-decorator/_js.view/source.js diff --git a/1-js/8-more-functions/08-call-apply-decorators/2-spy-decorator/_js.view/test.js b/1-js/06-more-functions/08-call-apply-decorators/01-spy-decorator/_js.view/test.js similarity index 100% rename from 1-js/8-more-functions/08-call-apply-decorators/2-spy-decorator/_js.view/test.js rename to 1-js/06-more-functions/08-call-apply-decorators/01-spy-decorator/_js.view/test.js diff --git a/1-js/8-more-functions/08-call-apply-decorators/2-spy-decorator/solution.md b/1-js/06-more-functions/08-call-apply-decorators/01-spy-decorator/solution.md similarity index 100% rename from 1-js/8-more-functions/08-call-apply-decorators/2-spy-decorator/solution.md rename to 1-js/06-more-functions/08-call-apply-decorators/01-spy-decorator/solution.md diff --git a/1-js/8-more-functions/08-call-apply-decorators/2-spy-decorator/task.md b/1-js/06-more-functions/08-call-apply-decorators/01-spy-decorator/task.md similarity index 100% rename from 1-js/8-more-functions/08-call-apply-decorators/2-spy-decorator/task.md rename to 1-js/06-more-functions/08-call-apply-decorators/01-spy-decorator/task.md diff --git a/archive/1-delay/_js.view/solution.js b/1-js/06-more-functions/08-call-apply-decorators/02-delay/_js.view/solution.js similarity index 100% rename from archive/1-delay/_js.view/solution.js rename to 1-js/06-more-functions/08-call-apply-decorators/02-delay/_js.view/solution.js diff --git a/archive/1-delay/_js.view/test.js b/1-js/06-more-functions/08-call-apply-decorators/02-delay/_js.view/test.js similarity index 53% rename from archive/1-delay/_js.view/test.js rename to 1-js/06-more-functions/08-call-apply-decorators/02-delay/_js.view/test.js index 964ccf60..d9295da5 100644 --- a/archive/1-delay/_js.view/test.js +++ b/1-js/06-more-functions/08-call-apply-decorators/02-delay/_js.view/test.js @@ -7,40 +7,40 @@ describe("delay", function() { this.clock.restore(); }); - it("вызывает функцию через указанный таймаут", function() { - var start = Date.now(); + it("calls the function after the specified timeout", function() { + let start = Date.now(); function f(x) { assert.equal(Date.now() - start, 1000); } f = sinon.spy(f); - var f1000 = delay(f, 1000); + let f1000 = delay(f, 1000); f1000("test"); this.clock.tick(2000); assert(f.calledOnce, 'calledOnce check fails'); }); - it("передаёт аргументы и контекст", function() { - var start = Date.now(); - var user = { + it("passes arguments and this", function() { + let start = Date.now(); + let user = { sayHi: function(phrase, who) { assert.equal(this, user); - assert.equal(phrase, "Привет"); - assert.equal(who, "Вася"); + assert.equal(phrase, "Hello"); + assert.equal(who, "John"); assert.equal(Date.now() - start, 1500); } }; user.sayHi = sinon.spy(user.sayHi); - var spy = user.sayHi; + let spy = user.sayHi; user.sayHi = delay(user.sayHi, 1500); - user.sayHi("Привет", "Вася"); + user.sayHi("Hello", "John"); this.clock.tick(2000); - assert(spy.calledOnce, 'проверка calledOnce не сработала'); + assert(spy.calledOnce, 'calledOnce check failed'); }); -}); \ No newline at end of file +}); diff --git a/1-js/06-more-functions/08-call-apply-decorators/02-delay/solution.md b/1-js/06-more-functions/08-call-apply-decorators/02-delay/solution.md new file mode 100644 index 00000000..44b5024e --- /dev/null +++ b/1-js/06-more-functions/08-call-apply-decorators/02-delay/solution.md @@ -0,0 +1,29 @@ +The solution: + +```js +function delay(f, ms) { + + return function() { + setTimeout(() => f.apply(this, arguments), ms); + }; + +} +``` + +Please note how an arrow function is used here. As we know, arrow functions do not have own `this` and `arguments`, so `f.apply(this, arguments)` takes `this` and `arguments` from the wrapper. + +If we pass a regular function, `setTimeout` would call it without arguments and `this=window` (in-browser), so we'd need to write a bit more code to pass them from the wrapper: + +```js +function delay(f, ms) { + + // added variables to pass this and arguments from the wrapper inside setTimeout + return function(...args) { + let savedThis = this; + setTimeout(function() { + f.apply(savedThis, args); + }, ms); + }; + +} +``` diff --git a/archive/1-delay/task.md b/1-js/06-more-functions/08-call-apply-decorators/02-delay/task.md similarity index 92% rename from archive/1-delay/task.md rename to 1-js/06-more-functions/08-call-apply-decorators/02-delay/task.md index 5669f7bb..c04c68d7 100644 --- a/archive/1-delay/task.md +++ b/1-js/06-more-functions/08-call-apply-decorators/02-delay/task.md @@ -2,7 +2,7 @@ importance: 5 --- -# Delaying decorator [todo move after arrow] +# Delaying decorator Create a decorator `delay(f, ms)` that delays each call of `f` by `ms` milliseconds. @@ -24,4 +24,3 @@ f1500("test"); // shows "test" after 1500ms In other words, `delay(f, ms)` returns a "delayed by `ms`" variant of `f`. In the code above, `f` is a function of a single argument, but your solution should pass all arguments and the context `this`. - diff --git a/1-js/8-more-functions/08-call-apply-decorators/8-debounce/_js.view/solution.js b/1-js/06-more-functions/08-call-apply-decorators/03-debounce/_js.view/solution.js similarity index 100% rename from 1-js/8-more-functions/08-call-apply-decorators/8-debounce/_js.view/solution.js rename to 1-js/06-more-functions/08-call-apply-decorators/03-debounce/_js.view/solution.js diff --git a/1-js/8-more-functions/08-call-apply-decorators/8-debounce/_js.view/test.js b/1-js/06-more-functions/08-call-apply-decorators/03-debounce/_js.view/test.js similarity index 100% rename from 1-js/8-more-functions/08-call-apply-decorators/8-debounce/_js.view/test.js rename to 1-js/06-more-functions/08-call-apply-decorators/03-debounce/_js.view/test.js diff --git a/1-js/8-more-functions/08-call-apply-decorators/8-debounce/solution.md b/1-js/06-more-functions/08-call-apply-decorators/03-debounce/solution.md similarity index 100% rename from 1-js/8-more-functions/08-call-apply-decorators/8-debounce/solution.md rename to 1-js/06-more-functions/08-call-apply-decorators/03-debounce/solution.md diff --git a/1-js/8-more-functions/08-call-apply-decorators/8-debounce/task.md b/1-js/06-more-functions/08-call-apply-decorators/03-debounce/task.md similarity index 100% rename from 1-js/8-more-functions/08-call-apply-decorators/8-debounce/task.md rename to 1-js/06-more-functions/08-call-apply-decorators/03-debounce/task.md diff --git a/1-js/8-more-functions/08-call-apply-decorators/9-throttle/_js.view/solution.js b/1-js/06-more-functions/08-call-apply-decorators/04-throttle/_js.view/solution.js similarity index 100% rename from 1-js/8-more-functions/08-call-apply-decorators/9-throttle/_js.view/solution.js rename to 1-js/06-more-functions/08-call-apply-decorators/04-throttle/_js.view/solution.js diff --git a/1-js/8-more-functions/08-call-apply-decorators/9-throttle/_js.view/test.js b/1-js/06-more-functions/08-call-apply-decorators/04-throttle/_js.view/test.js similarity index 100% rename from 1-js/8-more-functions/08-call-apply-decorators/9-throttle/_js.view/test.js rename to 1-js/06-more-functions/08-call-apply-decorators/04-throttle/_js.view/test.js diff --git a/1-js/8-more-functions/08-call-apply-decorators/9-throttle/solution.md b/1-js/06-more-functions/08-call-apply-decorators/04-throttle/solution.md similarity index 100% rename from 1-js/8-more-functions/08-call-apply-decorators/9-throttle/solution.md rename to 1-js/06-more-functions/08-call-apply-decorators/04-throttle/solution.md diff --git a/1-js/8-more-functions/08-call-apply-decorators/9-throttle/task.md b/1-js/06-more-functions/08-call-apply-decorators/04-throttle/task.md similarity index 100% rename from 1-js/8-more-functions/08-call-apply-decorators/9-throttle/task.md rename to 1-js/06-more-functions/08-call-apply-decorators/04-throttle/task.md diff --git a/1-js/8-more-functions/08-call-apply-decorators/article.md b/1-js/06-more-functions/08-call-apply-decorators/article.md similarity index 85% rename from 1-js/8-more-functions/08-call-apply-decorators/article.md rename to 1-js/06-more-functions/08-call-apply-decorators/article.md index db99676d..80ba2154 100644 --- a/1-js/8-more-functions/08-call-apply-decorators/article.md +++ b/1-js/06-more-functions/08-call-apply-decorators/article.md @@ -6,9 +6,11 @@ Javascript gives exceptional flexibility when dealing with functions. They can b ## Transparent caching -Let's say we have a function `slow(x)` which is CPU-heavy, but its results are stable. In other words, for same `x` it always returns the same result. +Let's say we have a function `slow(x)` which is CPU-heavy, but its results are stable. In other words, for the same `x` it always returns the same result. -If the function is called often, we may want to create a wrapper that caches (remembers) results for different `x`, to evade spending extra-time on recalculations. +If the function is called often, we may want to cache (remember) the results for different `x` to evade spending extra-time on recalculations. + +But instead of adding that functionality into `slow()` we'll create a wrapper. As we'll see, there are many benefits of doing so. Here's the code, and explanations follow: @@ -45,9 +47,9 @@ alert( "Again: " + slow(2) ); // the same as the previous line In the code above `cachingDecorator` is a *decorator*: a special function that takes another function and alters its behavior. -The idea is that we can call `cachingDecorator` for any function and get its "caching" variant. That's great, because we can have many functions that could use such a feature, and all we need to do is to apply `cachingDecorator` to them. +The idea is that we can call `cachingDecorator` for any function, and it will return the caching wrapper. That's great, because we can have many functions that could use such a feature, and all we need to do is to apply `cachingDecorator` to them. -No need to modify the code of `slow` to add a feature -- we separate concerns and keep it simple. +By separating caching from the main function code we also keep the main code simpler. Now let's get into details of how it works. @@ -55,10 +57,9 @@ The result of `cachingDecorator(func)` is a "wrapper": `function(x)` that "wraps ![](decorator-makecaching-wrapper.png) -As we can see, the wrapper does not change the result here. From an outside code, the wrapped `slow` function still does the same. It just got a caching aspect added to its behavior. +As we can see, the wrapper returns the result of `func(x)` "as is". From an outside code, the wrapped `slow` function still does the same. It just got a caching aspect added to its behavior. - -There are several benefits of using a separate `cachingDecorator` instead of altering the code of `slow` itself: +To summarize, there are several benefits of using a separate `cachingDecorator` instead of altering the code of `slow` itself: - The `cachingDecorator` is reusable. We can apply it to another function. - The caching logic is separate, it did not increase the complexity of `slow` itself (if there were any). @@ -219,7 +220,7 @@ To put all clear, let's see more deeply how `this` is passed along: Now let's make `cachingDecorator` even more universal. Till now it was working only with single-argument functions. -Now how to cache this `obj.slow`? +Now how to cache the multi-argument `worker.slow` method? ```js let worker = { @@ -234,17 +235,16 @@ worker.slow = cachingDecorator(worker.slow); We have two tasks to solve here. -First is how to use both arguments `min` and `max` for the key in `cache` map. Previously, for a single argument `x` we could just `cache.set(x, result)` to save the result and `cache.get(x)` to retrieve it. - -But now we need to remember the result for a *combination of arguments*. The native `Map` takes single value only as the key. +First is how to use both arguments `min` and `max` for the key in `cache` map. Previously, for a single argument `x` we could just `cache.set(x, result)` to save the result and `cache.get(x)` to retrieve it. But now we need to remember the result for a *combination of arguments* `(min,max)`. The native `Map` takes single value only as the key. There are many solutions possible: -1. Implement (or use a third-party) a new map-like data structure that is more versatile and allows multi-keys. +1. Implement a new (or use a third-party) map-like data structure that is more versatile and allows multi-keys. 2. Use nested maps: `cache.set(min)` will be a `Map` that stores the pair `(max, result)`. So we can get `result` as `cache.get(min).get(max)`. -3. Allow to provide a *hashing function* for the decorator, that knows how to make a one value from many. +3. Join two values into one. In our particular case we can just use a string `"min,max"` as the `Map` key. For flexibility, we can allow to provide a *hashing function* for the decorator, that knows how to make a one value from many. -For our case and many practical applications, the 3rd variant is good enough. + +For many practical applications, the 3rd variant is good enough, so we'll stick to it. The second task to solve is how to pass many arguments to `func`. Currently, the wrapper `function(x)` assumes a single argument, and `func.call(this, x)` passes it. @@ -307,9 +307,9 @@ If we look more closely, there's a minor difference between such uses of `call` So, these calls complement to each other. Where we expect an iterable, `call` works, where we expect an array-like, `apply` works. -If something is both iterable and array-like, like a real array, then we technically could use any of them, but `apply` will probably be faster, because it's a single operation, more optimized inside the engines internally than a pair `call + spread`. +And if `args` is both iterable and array-like, like a real array, then we technically could use any of them, but `apply` will probably be faster, because it's a single operation. Most Javascript engines internally optimize is better than a pair `call + spread`. -We can use `apply` to pass everything to another function like this: +One of most important uses of `apply` is passing the call to another function, like this: ```js let wrapper = function() { @@ -321,7 +321,7 @@ That's called *call forwarding*. The `wrapper` passes everything it gets: the co When an external code calls such `wrapper`, it is undistinguishable from the call of the original function. -Finally, let's bake it all into the more powerful `cachingDecorator`: +Now let's bake it all into the more powerful `cachingDecorator`: ```js run let worker = { @@ -364,7 +364,7 @@ Now the wrapper operates with any number of arguments. There are two changes: -- In the line `(*)` it calls `hash` to create a single key from `arguments`. Here we use a simple "glue" function that turns `(3, 5)` into key `"3,5"`. More complex cases may require other hashing functions. +- In the line `(*)` it calls `hash` to create a single key from `arguments`. Here we use a simple "joining" function that turns arguments `(3, 5)` into the key `"3,5"`. More complex cases may require other hashing functions. - Then `(**)` uses `func.apply` to pass both the context and all arguments the wrapper got (no matter how many) to the original function. diff --git a/1-js/8-more-functions/08-call-apply-decorators/decorator-makecaching-wrapper.png b/1-js/06-more-functions/08-call-apply-decorators/decorator-makecaching-wrapper.png similarity index 100% rename from 1-js/8-more-functions/08-call-apply-decorators/decorator-makecaching-wrapper.png rename to 1-js/06-more-functions/08-call-apply-decorators/decorator-makecaching-wrapper.png diff --git a/1-js/8-more-functions/08-call-apply-decorators/decorator-makecaching-wrapper@2x.png b/1-js/06-more-functions/08-call-apply-decorators/decorator-makecaching-wrapper@2x.png similarity index 100% rename from 1-js/8-more-functions/08-call-apply-decorators/decorator-makecaching-wrapper@2x.png rename to 1-js/06-more-functions/08-call-apply-decorators/decorator-makecaching-wrapper@2x.png diff --git a/1-js/8-more-functions/09-bind/2-write-to-object-after-bind/solution.md b/1-js/06-more-functions/09-bind/2-write-to-object-after-bind/solution.md similarity index 100% rename from 1-js/8-more-functions/09-bind/2-write-to-object-after-bind/solution.md rename to 1-js/06-more-functions/09-bind/2-write-to-object-after-bind/solution.md diff --git a/1-js/8-more-functions/09-bind/2-write-to-object-after-bind/task.md b/1-js/06-more-functions/09-bind/2-write-to-object-after-bind/task.md similarity index 100% rename from 1-js/8-more-functions/09-bind/2-write-to-object-after-bind/task.md rename to 1-js/06-more-functions/09-bind/2-write-to-object-after-bind/task.md diff --git a/1-js/8-more-functions/09-bind/3-second-bind/solution.md b/1-js/06-more-functions/09-bind/3-second-bind/solution.md similarity index 100% rename from 1-js/8-more-functions/09-bind/3-second-bind/solution.md rename to 1-js/06-more-functions/09-bind/3-second-bind/solution.md diff --git a/1-js/8-more-functions/09-bind/3-second-bind/task.md b/1-js/06-more-functions/09-bind/3-second-bind/task.md similarity index 100% rename from 1-js/8-more-functions/09-bind/3-second-bind/task.md rename to 1-js/06-more-functions/09-bind/3-second-bind/task.md diff --git a/1-js/8-more-functions/09-bind/4-function-property-after-bind/solution.md b/1-js/06-more-functions/09-bind/4-function-property-after-bind/solution.md similarity index 100% rename from 1-js/8-more-functions/09-bind/4-function-property-after-bind/solution.md rename to 1-js/06-more-functions/09-bind/4-function-property-after-bind/solution.md diff --git a/1-js/8-more-functions/09-bind/4-function-property-after-bind/task.md b/1-js/06-more-functions/09-bind/4-function-property-after-bind/task.md similarity index 100% rename from 1-js/8-more-functions/09-bind/4-function-property-after-bind/task.md rename to 1-js/06-more-functions/09-bind/4-function-property-after-bind/task.md diff --git a/1-js/8-more-functions/09-bind/5-question-use-bind/solution.md b/1-js/06-more-functions/09-bind/5-question-use-bind/solution.md similarity index 100% rename from 1-js/8-more-functions/09-bind/5-question-use-bind/solution.md rename to 1-js/06-more-functions/09-bind/5-question-use-bind/solution.md diff --git a/1-js/8-more-functions/09-bind/5-question-use-bind/task.md b/1-js/06-more-functions/09-bind/5-question-use-bind/task.md similarity index 100% rename from 1-js/8-more-functions/09-bind/5-question-use-bind/task.md rename to 1-js/06-more-functions/09-bind/5-question-use-bind/task.md diff --git a/1-js/8-more-functions/09-bind/6-ask-currying/solution.md b/1-js/06-more-functions/09-bind/6-ask-currying/solution.md similarity index 100% rename from 1-js/8-more-functions/09-bind/6-ask-currying/solution.md rename to 1-js/06-more-functions/09-bind/6-ask-currying/solution.md diff --git a/1-js/8-more-functions/09-bind/6-ask-currying/task.md b/1-js/06-more-functions/09-bind/6-ask-currying/task.md similarity index 100% rename from 1-js/8-more-functions/09-bind/6-ask-currying/task.md rename to 1-js/06-more-functions/09-bind/6-ask-currying/task.md diff --git a/1-js/8-more-functions/09-bind/article.md b/1-js/06-more-functions/09-bind/article.md similarity index 100% rename from 1-js/8-more-functions/09-bind/article.md rename to 1-js/06-more-functions/09-bind/article.md diff --git a/1-js/8-more-functions/09-bind/head.html b/1-js/06-more-functions/09-bind/head.html similarity index 100% rename from 1-js/8-more-functions/09-bind/head.html rename to 1-js/06-more-functions/09-bind/head.html diff --git a/1-js/8-more-functions/10-arrow-functions/article.md b/1-js/06-more-functions/10-arrow-functions/article.md similarity index 100% rename from 1-js/8-more-functions/10-arrow-functions/article.md rename to 1-js/06-more-functions/10-arrow-functions/article.md diff --git a/1-js/8-more-functions/index.md b/1-js/06-more-functions/index.md similarity index 100% rename from 1-js/8-more-functions/index.md rename to 1-js/06-more-functions/index.md diff --git a/1-js/9-object-inheritance/01-property-flags-descriptors/article.md b/1-js/07-object-inheritance/01-property-flags-descriptors/article.md similarity index 100% rename from 1-js/9-object-inheritance/01-property-flags-descriptors/article.md rename to 1-js/07-object-inheritance/01-property-flags-descriptors/article.md diff --git a/1-js/9-object-inheritance/02-property-accessors/article.md b/1-js/07-object-inheritance/02-property-accessors/article.md similarity index 100% rename from 1-js/9-object-inheritance/02-property-accessors/article.md rename to 1-js/07-object-inheritance/02-property-accessors/article.md diff --git a/1-js/9-object-inheritance/03-prototype/1-property-after-delete/solution.md b/1-js/07-object-inheritance/03-prototype/1-property-after-delete/solution.md similarity index 100% rename from 1-js/9-object-inheritance/03-prototype/1-property-after-delete/solution.md rename to 1-js/07-object-inheritance/03-prototype/1-property-after-delete/solution.md diff --git a/1-js/9-object-inheritance/03-prototype/1-property-after-delete/task.md b/1-js/07-object-inheritance/03-prototype/1-property-after-delete/task.md similarity index 100% rename from 1-js/9-object-inheritance/03-prototype/1-property-after-delete/task.md rename to 1-js/07-object-inheritance/03-prototype/1-property-after-delete/task.md diff --git a/1-js/9-object-inheritance/03-prototype/2-search-algorithm/solution.md b/1-js/07-object-inheritance/03-prototype/2-search-algorithm/solution.md similarity index 100% rename from 1-js/9-object-inheritance/03-prototype/2-search-algorithm/solution.md rename to 1-js/07-object-inheritance/03-prototype/2-search-algorithm/solution.md diff --git a/1-js/9-object-inheritance/03-prototype/2-search-algorithm/task.md b/1-js/07-object-inheritance/03-prototype/2-search-algorithm/task.md similarity index 100% rename from 1-js/9-object-inheritance/03-prototype/2-search-algorithm/task.md rename to 1-js/07-object-inheritance/03-prototype/2-search-algorithm/task.md diff --git a/1-js/9-object-inheritance/03-prototype/3-proto-and-this/solution.md b/1-js/07-object-inheritance/03-prototype/3-proto-and-this/solution.md similarity index 100% rename from 1-js/9-object-inheritance/03-prototype/3-proto-and-this/solution.md rename to 1-js/07-object-inheritance/03-prototype/3-proto-and-this/solution.md diff --git a/1-js/9-object-inheritance/03-prototype/3-proto-and-this/task.md b/1-js/07-object-inheritance/03-prototype/3-proto-and-this/task.md similarity index 100% rename from 1-js/9-object-inheritance/03-prototype/3-proto-and-this/task.md rename to 1-js/07-object-inheritance/03-prototype/3-proto-and-this/task.md diff --git a/1-js/9-object-inheritance/03-prototype/4-hamster-proto/solution.md b/1-js/07-object-inheritance/03-prototype/4-hamster-proto/solution.md similarity index 100% rename from 1-js/9-object-inheritance/03-prototype/4-hamster-proto/solution.md rename to 1-js/07-object-inheritance/03-prototype/4-hamster-proto/solution.md diff --git a/1-js/9-object-inheritance/03-prototype/4-hamster-proto/task.md b/1-js/07-object-inheritance/03-prototype/4-hamster-proto/task.md similarity index 100% rename from 1-js/9-object-inheritance/03-prototype/4-hamster-proto/task.md rename to 1-js/07-object-inheritance/03-prototype/4-hamster-proto/task.md diff --git a/1-js/9-object-inheritance/03-prototype/article.md b/1-js/07-object-inheritance/03-prototype/article.md similarity index 88% rename from 1-js/9-object-inheritance/03-prototype/article.md rename to 1-js/07-object-inheritance/03-prototype/article.md index 0be5c383..03934dd7 100644 --- a/1-js/9-object-inheritance/03-prototype/article.md +++ b/1-js/07-object-inheritance/03-prototype/article.md @@ -11,7 +11,7 @@ For instance, we have a `user` object with its properties and methods, and want ## [[Prototype]] -In Javascript, objects have a special hidden property `[[Prototype]]`, that is either `null` or references another object. That object is called "a prototype": +In Javascript, objects have a special hidden property `[[Prototype]]` (as named in the specification), that is either `null` or references another object. That object is called "a prototype": ![prototype](object-prototype-empty.png) @@ -244,4 +244,10 @@ If we had other objects like `bird`, `snake` etc inheriting from `animal`, they In other words, methods are shared, but the state will be not. -## Summary [todo] +## Summary + +- In Javascript, all objects have a hidden `[[Prototype]]` property that's either another object or `null`. +- We can use `obj.__proto__` to access it (there are other ways too, to be covered soon). +- The object references by `[[Prototype]]` is called a "prototype". +- If we want to read a property of `obj` or call a method, and it doesn't exist, then Javascript tries to find it in the prototype. Write/delete operations work directly on the object, they don't use the prototype (unless the property is actually a setter). +- If we call `obj.method()`, and the `method` is taken from the prototype, `this` still references `obj`. So methods always work with the current objects even if they are inherited. diff --git a/1-js/9-object-inheritance/03-prototype/object-prototype-empty.png b/1-js/07-object-inheritance/03-prototype/object-prototype-empty.png similarity index 100% rename from 1-js/9-object-inheritance/03-prototype/object-prototype-empty.png rename to 1-js/07-object-inheritance/03-prototype/object-prototype-empty.png diff --git a/1-js/9-object-inheritance/03-prototype/object-prototype-empty@2x.png b/1-js/07-object-inheritance/03-prototype/object-prototype-empty@2x.png similarity index 100% rename from 1-js/9-object-inheritance/03-prototype/object-prototype-empty@2x.png rename to 1-js/07-object-inheritance/03-prototype/object-prototype-empty@2x.png diff --git a/1-js/9-object-inheritance/03-prototype/proto-animal-rabbit-chain.png b/1-js/07-object-inheritance/03-prototype/proto-animal-rabbit-chain.png similarity index 100% rename from 1-js/9-object-inheritance/03-prototype/proto-animal-rabbit-chain.png rename to 1-js/07-object-inheritance/03-prototype/proto-animal-rabbit-chain.png diff --git a/1-js/9-object-inheritance/03-prototype/proto-animal-rabbit-chain@2x.png b/1-js/07-object-inheritance/03-prototype/proto-animal-rabbit-chain@2x.png similarity index 100% rename from 1-js/9-object-inheritance/03-prototype/proto-animal-rabbit-chain@2x.png rename to 1-js/07-object-inheritance/03-prototype/proto-animal-rabbit-chain@2x.png diff --git a/1-js/9-object-inheritance/03-prototype/proto-animal-rabbit-walk-2.png b/1-js/07-object-inheritance/03-prototype/proto-animal-rabbit-walk-2.png similarity index 100% rename from 1-js/9-object-inheritance/03-prototype/proto-animal-rabbit-walk-2.png rename to 1-js/07-object-inheritance/03-prototype/proto-animal-rabbit-walk-2.png diff --git a/1-js/9-object-inheritance/03-prototype/proto-animal-rabbit-walk-2@2x.png b/1-js/07-object-inheritance/03-prototype/proto-animal-rabbit-walk-2@2x.png similarity index 100% rename from 1-js/9-object-inheritance/03-prototype/proto-animal-rabbit-walk-2@2x.png rename to 1-js/07-object-inheritance/03-prototype/proto-animal-rabbit-walk-2@2x.png diff --git a/1-js/9-object-inheritance/03-prototype/proto-animal-rabbit-walk-3.png b/1-js/07-object-inheritance/03-prototype/proto-animal-rabbit-walk-3.png similarity index 100% rename from 1-js/9-object-inheritance/03-prototype/proto-animal-rabbit-walk-3.png rename to 1-js/07-object-inheritance/03-prototype/proto-animal-rabbit-walk-3.png diff --git a/1-js/9-object-inheritance/03-prototype/proto-animal-rabbit-walk-3@2x.png b/1-js/07-object-inheritance/03-prototype/proto-animal-rabbit-walk-3@2x.png similarity index 100% rename from 1-js/9-object-inheritance/03-prototype/proto-animal-rabbit-walk-3@2x.png rename to 1-js/07-object-inheritance/03-prototype/proto-animal-rabbit-walk-3@2x.png diff --git a/1-js/9-object-inheritance/03-prototype/proto-animal-rabbit-walk.png b/1-js/07-object-inheritance/03-prototype/proto-animal-rabbit-walk.png similarity index 100% rename from 1-js/9-object-inheritance/03-prototype/proto-animal-rabbit-walk.png rename to 1-js/07-object-inheritance/03-prototype/proto-animal-rabbit-walk.png diff --git a/1-js/9-object-inheritance/03-prototype/proto-animal-rabbit-walk@2x.png b/1-js/07-object-inheritance/03-prototype/proto-animal-rabbit-walk@2x.png similarity index 100% rename from 1-js/9-object-inheritance/03-prototype/proto-animal-rabbit-walk@2x.png rename to 1-js/07-object-inheritance/03-prototype/proto-animal-rabbit-walk@2x.png diff --git a/1-js/9-object-inheritance/03-prototype/proto-animal-rabbit.png b/1-js/07-object-inheritance/03-prototype/proto-animal-rabbit.png similarity index 100% rename from 1-js/9-object-inheritance/03-prototype/proto-animal-rabbit.png rename to 1-js/07-object-inheritance/03-prototype/proto-animal-rabbit.png diff --git a/1-js/9-object-inheritance/03-prototype/proto-animal-rabbit@2x.png b/1-js/07-object-inheritance/03-prototype/proto-animal-rabbit@2x.png similarity index 100% rename from 1-js/9-object-inheritance/03-prototype/proto-animal-rabbit@2x.png rename to 1-js/07-object-inheritance/03-prototype/proto-animal-rabbit@2x.png diff --git a/1-js/9-object-inheritance/03-prototype/proto-user-admin.png b/1-js/07-object-inheritance/03-prototype/proto-user-admin.png similarity index 100% rename from 1-js/9-object-inheritance/03-prototype/proto-user-admin.png rename to 1-js/07-object-inheritance/03-prototype/proto-user-admin.png diff --git a/1-js/9-object-inheritance/03-prototype/proto-user-admin@2x.png b/1-js/07-object-inheritance/03-prototype/proto-user-admin@2x.png similarity index 100% rename from 1-js/9-object-inheritance/03-prototype/proto-user-admin@2x.png rename to 1-js/07-object-inheritance/03-prototype/proto-user-admin@2x.png diff --git a/1-js/9-object-inheritance/04-function-prototype/1-changing-prototype/solution.md b/1-js/07-object-inheritance/04-function-prototype/1-changing-prototype/solution.md similarity index 100% rename from 1-js/9-object-inheritance/04-function-prototype/1-changing-prototype/solution.md rename to 1-js/07-object-inheritance/04-function-prototype/1-changing-prototype/solution.md diff --git a/1-js/9-object-inheritance/04-function-prototype/1-changing-prototype/task.md b/1-js/07-object-inheritance/04-function-prototype/1-changing-prototype/task.md similarity index 100% rename from 1-js/9-object-inheritance/04-function-prototype/1-changing-prototype/task.md rename to 1-js/07-object-inheritance/04-function-prototype/1-changing-prototype/task.md diff --git a/1-js/9-object-inheritance/05-native-prototypes/4-new-object-same-constructor/solution.md b/1-js/07-object-inheritance/04-function-prototype/4-new-object-same-constructor/solution.md similarity index 100% rename from 1-js/9-object-inheritance/05-native-prototypes/4-new-object-same-constructor/solution.md rename to 1-js/07-object-inheritance/04-function-prototype/4-new-object-same-constructor/solution.md diff --git a/1-js/9-object-inheritance/05-native-prototypes/4-new-object-same-constructor/task.md b/1-js/07-object-inheritance/04-function-prototype/4-new-object-same-constructor/task.md similarity index 100% rename from 1-js/9-object-inheritance/05-native-prototypes/4-new-object-same-constructor/task.md rename to 1-js/07-object-inheritance/04-function-prototype/4-new-object-same-constructor/task.md diff --git a/1-js/9-object-inheritance/04-function-prototype/article.md b/1-js/07-object-inheritance/04-function-prototype/article.md similarity index 100% rename from 1-js/9-object-inheritance/04-function-prototype/article.md rename to 1-js/07-object-inheritance/04-function-prototype/article.md diff --git a/1-js/9-object-inheritance/04-function-prototype/function-prototype-constructor.png b/1-js/07-object-inheritance/04-function-prototype/function-prototype-constructor.png similarity index 100% rename from 1-js/9-object-inheritance/04-function-prototype/function-prototype-constructor.png rename to 1-js/07-object-inheritance/04-function-prototype/function-prototype-constructor.png diff --git a/1-js/9-object-inheritance/04-function-prototype/function-prototype-constructor@2x.png b/1-js/07-object-inheritance/04-function-prototype/function-prototype-constructor@2x.png similarity index 100% rename from 1-js/9-object-inheritance/04-function-prototype/function-prototype-constructor@2x.png rename to 1-js/07-object-inheritance/04-function-prototype/function-prototype-constructor@2x.png diff --git a/1-js/9-object-inheritance/04-function-prototype/native-prototypes-array-tostring.png b/1-js/07-object-inheritance/04-function-prototype/native-prototypes-array-tostring.png similarity index 100% rename from 1-js/9-object-inheritance/04-function-prototype/native-prototypes-array-tostring.png rename to 1-js/07-object-inheritance/04-function-prototype/native-prototypes-array-tostring.png diff --git a/1-js/9-object-inheritance/04-function-prototype/native-prototypes-array-tostring@2x.png b/1-js/07-object-inheritance/04-function-prototype/native-prototypes-array-tostring@2x.png similarity index 100% rename from 1-js/9-object-inheritance/04-function-prototype/native-prototypes-array-tostring@2x.png rename to 1-js/07-object-inheritance/04-function-prototype/native-prototypes-array-tostring@2x.png diff --git a/1-js/9-object-inheritance/04-function-prototype/native-prototypes-classes.png b/1-js/07-object-inheritance/04-function-prototype/native-prototypes-classes.png similarity index 100% rename from 1-js/9-object-inheritance/04-function-prototype/native-prototypes-classes.png rename to 1-js/07-object-inheritance/04-function-prototype/native-prototypes-classes.png diff --git a/1-js/9-object-inheritance/04-function-prototype/native-prototypes-classes@2x.png b/1-js/07-object-inheritance/04-function-prototype/native-prototypes-classes@2x.png similarity index 100% rename from 1-js/9-object-inheritance/04-function-prototype/native-prototypes-classes@2x.png rename to 1-js/07-object-inheritance/04-function-prototype/native-prototypes-classes@2x.png diff --git a/1-js/9-object-inheritance/04-function-prototype/object-prototype-1.png b/1-js/07-object-inheritance/04-function-prototype/object-prototype-1.png similarity index 100% rename from 1-js/9-object-inheritance/04-function-prototype/object-prototype-1.png rename to 1-js/07-object-inheritance/04-function-prototype/object-prototype-1.png diff --git a/1-js/9-object-inheritance/04-function-prototype/object-prototype-1@2x.png b/1-js/07-object-inheritance/04-function-prototype/object-prototype-1@2x.png similarity index 100% rename from 1-js/9-object-inheritance/04-function-prototype/object-prototype-1@2x.png rename to 1-js/07-object-inheritance/04-function-prototype/object-prototype-1@2x.png diff --git a/1-js/9-object-inheritance/04-function-prototype/object-prototype.png b/1-js/07-object-inheritance/04-function-prototype/object-prototype.png similarity index 100% rename from 1-js/9-object-inheritance/04-function-prototype/object-prototype.png rename to 1-js/07-object-inheritance/04-function-prototype/object-prototype.png diff --git a/1-js/9-object-inheritance/04-function-prototype/object-prototype@2x.png b/1-js/07-object-inheritance/04-function-prototype/object-prototype@2x.png similarity index 100% rename from 1-js/9-object-inheritance/04-function-prototype/object-prototype@2x.png rename to 1-js/07-object-inheritance/04-function-prototype/object-prototype@2x.png diff --git a/1-js/9-object-inheritance/04-function-prototype/proto-constructor-animal-rabbit.png b/1-js/07-object-inheritance/04-function-prototype/proto-constructor-animal-rabbit.png similarity index 100% rename from 1-js/9-object-inheritance/04-function-prototype/proto-constructor-animal-rabbit.png rename to 1-js/07-object-inheritance/04-function-prototype/proto-constructor-animal-rabbit.png diff --git a/1-js/9-object-inheritance/04-function-prototype/proto-constructor-animal-rabbit@2x.png b/1-js/07-object-inheritance/04-function-prototype/proto-constructor-animal-rabbit@2x.png similarity index 100% rename from 1-js/9-object-inheritance/04-function-prototype/proto-constructor-animal-rabbit@2x.png rename to 1-js/07-object-inheritance/04-function-prototype/proto-constructor-animal-rabbit@2x.png diff --git a/1-js/9-object-inheritance/04-function-prototype/rabbit-animal-object.png b/1-js/07-object-inheritance/04-function-prototype/rabbit-animal-object.png similarity index 100% rename from 1-js/9-object-inheritance/04-function-prototype/rabbit-animal-object.png rename to 1-js/07-object-inheritance/04-function-prototype/rabbit-animal-object.png diff --git a/1-js/9-object-inheritance/04-function-prototype/rabbit-animal-object@2x.png b/1-js/07-object-inheritance/04-function-prototype/rabbit-animal-object@2x.png similarity index 100% rename from 1-js/9-object-inheritance/04-function-prototype/rabbit-animal-object@2x.png rename to 1-js/07-object-inheritance/04-function-prototype/rabbit-animal-object@2x.png diff --git a/1-js/9-object-inheritance/04-function-prototype/rabbit-prototype-constructor.png b/1-js/07-object-inheritance/04-function-prototype/rabbit-prototype-constructor.png similarity index 100% rename from 1-js/9-object-inheritance/04-function-prototype/rabbit-prototype-constructor.png rename to 1-js/07-object-inheritance/04-function-prototype/rabbit-prototype-constructor.png diff --git a/1-js/9-object-inheritance/04-function-prototype/rabbit-prototype-constructor@2x.png b/1-js/07-object-inheritance/04-function-prototype/rabbit-prototype-constructor@2x.png similarity index 100% rename from 1-js/9-object-inheritance/04-function-prototype/rabbit-prototype-constructor@2x.png rename to 1-js/07-object-inheritance/04-function-prototype/rabbit-prototype-constructor@2x.png diff --git a/1-js/07-object-inheritance/05-native-prototypes/1-defer-to-prototype/solution.md b/1-js/07-object-inheritance/05-native-prototypes/1-defer-to-prototype/solution.md new file mode 100644 index 00000000..ebd2f44e --- /dev/null +++ b/1-js/07-object-inheritance/05-native-prototypes/1-defer-to-prototype/solution.md @@ -0,0 +1,13 @@ + + +```js run +Function.prototype.defer = function(ms) { + setTimeout(this, ms); +}; + +function f() { + alert("Hello!"); +} + +f.defer(1000); // shows "Hello!" after 1 sec +``` diff --git a/1-js/07-object-inheritance/05-native-prototypes/1-defer-to-prototype/task.md b/1-js/07-object-inheritance/05-native-prototypes/1-defer-to-prototype/task.md new file mode 100644 index 00000000..d3b3a51c --- /dev/null +++ b/1-js/07-object-inheritance/05-native-prototypes/1-defer-to-prototype/task.md @@ -0,0 +1,17 @@ +importance: 5 + +--- + +# Add method "f.defer(ms)" to functions + +Add to the prototype of all functions the method `defer(ms)`, that runs the function after `ms` milliseconds. + +After you do it, such code should work: + +```js +function f() { + alert("Hello!"); +} + +f.defer(1000); // shows "Hello!" after 1 second +``` diff --git a/1-js/07-object-inheritance/05-native-prototypes/2-defer-to-prototype-extended/solution.md b/1-js/07-object-inheritance/05-native-prototypes/2-defer-to-prototype-extended/solution.md new file mode 100644 index 00000000..0bb18b44 --- /dev/null +++ b/1-js/07-object-inheritance/05-native-prototypes/2-defer-to-prototype-extended/solution.md @@ -0,0 +1,17 @@ + + +```js run +Function.prototype.defer = function(ms) { + var f = this; + return function(...args) { + setTimeout(() => f.apply(this, args), ms); + } +}; + +// check it +function f(a, b) { + alert( a + b ); +} + +f.defer(1000)(1, 2); // shows 3 after 1 sec +``` diff --git a/1-js/07-object-inheritance/05-native-prototypes/2-defer-to-prototype-extended/task.md b/1-js/07-object-inheritance/05-native-prototypes/2-defer-to-prototype-extended/task.md new file mode 100644 index 00000000..4d3823bb --- /dev/null +++ b/1-js/07-object-inheritance/05-native-prototypes/2-defer-to-prototype-extended/task.md @@ -0,0 +1,19 @@ +importance: 4 + +--- + +# Add the decorating "defer()" to functions + +Add to the prototype of all functions the method `defer(ms)`, that returns a wrapper, delaying the call by `ms` milliseconds. + +Here's an example of how it should work: + +```js +function f(a, b) { + alert( a + b ); +} + +f.defer(1000)(1, 2); // shows 3 after 1 second +``` + +Please note that the arguments should be passed to the original function. diff --git a/1-js/9-object-inheritance/05-native-prototypes/article.md b/1-js/07-object-inheritance/05-native-prototypes/article.md similarity index 82% rename from 1-js/9-object-inheritance/05-native-prototypes/article.md rename to 1-js/07-object-inheritance/05-native-prototypes/article.md index c6a05055..4265ef49 100644 --- a/1-js/9-object-inheritance/05-native-prototypes/article.md +++ b/1-js/07-object-inheritance/05-native-prototypes/article.md @@ -171,12 +171,10 @@ function showArgs() { That's more efficient, because evades creation of an extra array object `[]`. From the other side -- more letters to write it. -## Summary [todo] +## Summary -- Методы встроенных объектов хранятся в их прототипах. -- Встроенные прототипы можно расширить или поменять. -- Добавление методов в `Object.prototype`, если оно не сопровождается `Object.defineProperty` с установкой `enumerable` (IE9+), "сломает" циклы `for..in`, поэтому стараются в этот прототип методы не добавлять. - - Другие прототипы изменять менее опасно, но все же не рекомендуется во избежание конфликтов. - - Отдельно стоит изменение с целью добавления современных методов в старые браузеры, таких как Object.create, Object.keys, Function.prototype.bind и т.п. Это допустимо и как раз делается [es5-shim](https://github.com/kriskowal/es5-shim). +- All built-in objects follow the same pattern: + - The methods are stored in the prototype (`Array.prototype`, `Object.prototype`, `Date.prototype` etc). + - The object itself stores only the data (array items, object properties, the date). +- Primitives also store methods in prototypes of wrapper objects: `Number.prototype`, `String.prototype`, `Boolean.prototype`. There are no wrapper objects only for `undefined` and `null`. +- Built-in prototypes can be modified or populated with new methods. But it's not recommended to change them. Probably the only allowable cause is when we add-in a new standard, but not yet supported by the engine Javascript method. diff --git a/1-js/9-object-inheritance/05-native-prototypes/console_dir_array.png b/1-js/07-object-inheritance/05-native-prototypes/console_dir_array.png similarity index 100% rename from 1-js/9-object-inheritance/05-native-prototypes/console_dir_array.png rename to 1-js/07-object-inheritance/05-native-prototypes/console_dir_array.png diff --git a/1-js/9-object-inheritance/05-native-prototypes/function-prototype-constructor.png b/1-js/07-object-inheritance/05-native-prototypes/function-prototype-constructor.png similarity index 100% rename from 1-js/9-object-inheritance/05-native-prototypes/function-prototype-constructor.png rename to 1-js/07-object-inheritance/05-native-prototypes/function-prototype-constructor.png diff --git a/1-js/9-object-inheritance/05-native-prototypes/function-prototype-constructor@2x.png b/1-js/07-object-inheritance/05-native-prototypes/function-prototype-constructor@2x.png similarity index 100% rename from 1-js/9-object-inheritance/05-native-prototypes/function-prototype-constructor@2x.png rename to 1-js/07-object-inheritance/05-native-prototypes/function-prototype-constructor@2x.png diff --git a/1-js/9-object-inheritance/05-native-prototypes/native-prototypes-array-tostring.png b/1-js/07-object-inheritance/05-native-prototypes/native-prototypes-array-tostring.png similarity index 100% rename from 1-js/9-object-inheritance/05-native-prototypes/native-prototypes-array-tostring.png rename to 1-js/07-object-inheritance/05-native-prototypes/native-prototypes-array-tostring.png diff --git a/1-js/9-object-inheritance/05-native-prototypes/native-prototypes-array-tostring@2x.png b/1-js/07-object-inheritance/05-native-prototypes/native-prototypes-array-tostring@2x.png similarity index 100% rename from 1-js/9-object-inheritance/05-native-prototypes/native-prototypes-array-tostring@2x.png rename to 1-js/07-object-inheritance/05-native-prototypes/native-prototypes-array-tostring@2x.png diff --git a/1-js/9-object-inheritance/05-native-prototypes/native-prototypes-classes.png b/1-js/07-object-inheritance/05-native-prototypes/native-prototypes-classes.png similarity index 100% rename from 1-js/9-object-inheritance/05-native-prototypes/native-prototypes-classes.png rename to 1-js/07-object-inheritance/05-native-prototypes/native-prototypes-classes.png diff --git a/1-js/9-object-inheritance/05-native-prototypes/native-prototypes-classes@2x.png b/1-js/07-object-inheritance/05-native-prototypes/native-prototypes-classes@2x.png similarity index 100% rename from 1-js/9-object-inheritance/05-native-prototypes/native-prototypes-classes@2x.png rename to 1-js/07-object-inheritance/05-native-prototypes/native-prototypes-classes@2x.png diff --git a/1-js/9-object-inheritance/05-native-prototypes/object-prototype-1.png b/1-js/07-object-inheritance/05-native-prototypes/object-prototype-1.png similarity index 100% rename from 1-js/9-object-inheritance/05-native-prototypes/object-prototype-1.png rename to 1-js/07-object-inheritance/05-native-prototypes/object-prototype-1.png diff --git a/1-js/9-object-inheritance/05-native-prototypes/object-prototype-1@2x.png b/1-js/07-object-inheritance/05-native-prototypes/object-prototype-1@2x.png similarity index 100% rename from 1-js/9-object-inheritance/05-native-prototypes/object-prototype-1@2x.png rename to 1-js/07-object-inheritance/05-native-prototypes/object-prototype-1@2x.png diff --git a/1-js/9-object-inheritance/05-native-prototypes/object-prototype-null.png b/1-js/07-object-inheritance/05-native-prototypes/object-prototype-null.png similarity index 100% rename from 1-js/9-object-inheritance/05-native-prototypes/object-prototype-null.png rename to 1-js/07-object-inheritance/05-native-prototypes/object-prototype-null.png diff --git a/1-js/9-object-inheritance/05-native-prototypes/object-prototype-null@2x.png b/1-js/07-object-inheritance/05-native-prototypes/object-prototype-null@2x.png similarity index 100% rename from 1-js/9-object-inheritance/05-native-prototypes/object-prototype-null@2x.png rename to 1-js/07-object-inheritance/05-native-prototypes/object-prototype-null@2x.png diff --git a/1-js/9-object-inheritance/05-native-prototypes/object-prototype.png b/1-js/07-object-inheritance/05-native-prototypes/object-prototype.png similarity index 100% rename from 1-js/9-object-inheritance/05-native-prototypes/object-prototype.png rename to 1-js/07-object-inheritance/05-native-prototypes/object-prototype.png diff --git a/1-js/9-object-inheritance/05-native-prototypes/object-prototype@2x.png b/1-js/07-object-inheritance/05-native-prototypes/object-prototype@2x.png similarity index 100% rename from 1-js/9-object-inheritance/05-native-prototypes/object-prototype@2x.png rename to 1-js/07-object-inheritance/05-native-prototypes/object-prototype@2x.png diff --git a/1-js/9-object-inheritance/05-native-prototypes/proto-constructor-animal-rabbit.png b/1-js/07-object-inheritance/05-native-prototypes/proto-constructor-animal-rabbit.png similarity index 100% rename from 1-js/9-object-inheritance/05-native-prototypes/proto-constructor-animal-rabbit.png rename to 1-js/07-object-inheritance/05-native-prototypes/proto-constructor-animal-rabbit.png diff --git a/1-js/9-object-inheritance/05-native-prototypes/proto-constructor-animal-rabbit@2x.png b/1-js/07-object-inheritance/05-native-prototypes/proto-constructor-animal-rabbit@2x.png similarity index 100% rename from 1-js/9-object-inheritance/05-native-prototypes/proto-constructor-animal-rabbit@2x.png rename to 1-js/07-object-inheritance/05-native-prototypes/proto-constructor-animal-rabbit@2x.png diff --git a/1-js/9-object-inheritance/05-native-prototypes/rabbit-prototype-constructor.png b/1-js/07-object-inheritance/05-native-prototypes/rabbit-prototype-constructor.png similarity index 100% rename from 1-js/9-object-inheritance/05-native-prototypes/rabbit-prototype-constructor.png rename to 1-js/07-object-inheritance/05-native-prototypes/rabbit-prototype-constructor.png diff --git a/1-js/9-object-inheritance/05-native-prototypes/rabbit-prototype-constructor@2x.png b/1-js/07-object-inheritance/05-native-prototypes/rabbit-prototype-constructor@2x.png similarity index 100% rename from 1-js/9-object-inheritance/05-native-prototypes/rabbit-prototype-constructor@2x.png rename to 1-js/07-object-inheritance/05-native-prototypes/rabbit-prototype-constructor@2x.png diff --git a/1-js/9-object-inheritance/05-native-prototypes/2-dictionary-tostring/solution.md b/1-js/07-object-inheritance/06-prototype-methods/2-dictionary-tostring/solution.md similarity index 100% rename from 1-js/9-object-inheritance/05-native-prototypes/2-dictionary-tostring/solution.md rename to 1-js/07-object-inheritance/06-prototype-methods/2-dictionary-tostring/solution.md diff --git a/1-js/9-object-inheritance/05-native-prototypes/2-dictionary-tostring/task.md b/1-js/07-object-inheritance/06-prototype-methods/2-dictionary-tostring/task.md similarity index 62% rename from 1-js/9-object-inheritance/05-native-prototypes/2-dictionary-tostring/task.md rename to 1-js/07-object-inheritance/06-prototype-methods/2-dictionary-tostring/task.md index 039bc0ea..6eab6f9e 100644 --- a/1-js/9-object-inheritance/05-native-prototypes/2-dictionary-tostring/task.md +++ b/1-js/07-object-inheritance/06-prototype-methods/2-dictionary-tostring/task.md @@ -2,11 +2,11 @@ importance: 5 --- -# Add toString to dictionary +# Add toString to the dictionary There's an object `dictionary`, suited to store any `key/value` pairs. -Add `toString` for it, that would show a list of comma-delimited keys. Your `toString` should not show up in `for..in` over the object. +Add method `dictionary.toString()` into it, that should return a comma-delimited list of keys. Your `toString` should not show up in `for..in` over the object. Here's how it should work: @@ -19,7 +19,7 @@ let dictionary = Object.create(null); // add some data dictionary.apple = "Apple"; -dictionary.__proto__ = "test"; +dictionary.__proto__ = "test"; // __proto__ is a regular property key here // only apple and __proto__ are in the loop for(let key in dictionary) { @@ -29,4 +29,3 @@ for(let key in dictionary) { // your toString in action alert(dictionary); // "apple,__proto__" ``` - diff --git a/1-js/9-object-inheritance/05-native-prototypes/3-compare-calls/solution.md b/1-js/07-object-inheritance/06-prototype-methods/3-compare-calls/solution.md similarity index 100% rename from 1-js/9-object-inheritance/05-native-prototypes/3-compare-calls/solution.md rename to 1-js/07-object-inheritance/06-prototype-methods/3-compare-calls/solution.md diff --git a/1-js/9-object-inheritance/05-native-prototypes/3-compare-calls/task.md b/1-js/07-object-inheritance/06-prototype-methods/3-compare-calls/task.md similarity index 100% rename from 1-js/9-object-inheritance/05-native-prototypes/3-compare-calls/task.md rename to 1-js/07-object-inheritance/06-prototype-methods/3-compare-calls/task.md diff --git a/1-js/9-object-inheritance/06-prototype-methods/article.md b/1-js/07-object-inheritance/06-prototype-methods/article.md similarity index 100% rename from 1-js/9-object-inheritance/06-prototype-methods/article.md rename to 1-js/07-object-inheritance/06-prototype-methods/article.md diff --git a/1-js/9-object-inheritance/06-prototype-methods/object-prototype-2.png b/1-js/07-object-inheritance/06-prototype-methods/object-prototype-2.png similarity index 100% rename from 1-js/9-object-inheritance/06-prototype-methods/object-prototype-2.png rename to 1-js/07-object-inheritance/06-prototype-methods/object-prototype-2.png diff --git a/1-js/9-object-inheritance/06-prototype-methods/object-prototype-2@2x.png b/1-js/07-object-inheritance/06-prototype-methods/object-prototype-2@2x.png similarity index 100% rename from 1-js/9-object-inheritance/06-prototype-methods/object-prototype-2@2x.png rename to 1-js/07-object-inheritance/06-prototype-methods/object-prototype-2@2x.png diff --git a/1-js/9-object-inheritance/06-prototype-methods/object-prototype-null.png b/1-js/07-object-inheritance/06-prototype-methods/object-prototype-null.png similarity index 100% rename from 1-js/9-object-inheritance/06-prototype-methods/object-prototype-null.png rename to 1-js/07-object-inheritance/06-prototype-methods/object-prototype-null.png diff --git a/1-js/9-object-inheritance/06-prototype-methods/object-prototype-null@2x.png b/1-js/07-object-inheritance/06-prototype-methods/object-prototype-null@2x.png similarity index 100% rename from 1-js/9-object-inheritance/06-prototype-methods/object-prototype-null@2x.png rename to 1-js/07-object-inheritance/06-prototype-methods/object-prototype-null@2x.png diff --git a/1-js/9-object-inheritance/06-prototype-methods/rabbit-animal-object.png b/1-js/07-object-inheritance/06-prototype-methods/rabbit-animal-object.png similarity index 100% rename from 1-js/9-object-inheritance/06-prototype-methods/rabbit-animal-object.png rename to 1-js/07-object-inheritance/06-prototype-methods/rabbit-animal-object.png diff --git a/1-js/9-object-inheritance/06-prototype-methods/rabbit-animal-object@2x.png b/1-js/07-object-inheritance/06-prototype-methods/rabbit-animal-object@2x.png similarity index 100% rename from 1-js/9-object-inheritance/06-prototype-methods/rabbit-animal-object@2x.png rename to 1-js/07-object-inheritance/06-prototype-methods/rabbit-animal-object@2x.png diff --git a/1-js/9-object-inheritance/08-class-patterns/1-inheritance-error-assign/solution.md b/1-js/07-object-inheritance/08-class-patterns/1-inheritance-error-assign/solution.md similarity index 100% rename from 1-js/9-object-inheritance/08-class-patterns/1-inheritance-error-assign/solution.md rename to 1-js/07-object-inheritance/08-class-patterns/1-inheritance-error-assign/solution.md diff --git a/1-js/9-object-inheritance/08-class-patterns/1-inheritance-error-assign/task.md b/1-js/07-object-inheritance/08-class-patterns/1-inheritance-error-assign/task.md similarity index 100% rename from 1-js/9-object-inheritance/08-class-patterns/1-inheritance-error-assign/task.md rename to 1-js/07-object-inheritance/08-class-patterns/1-inheritance-error-assign/task.md diff --git a/1-js/9-object-inheritance/08-class-patterns/2-rewrite-to-prototypes/solution.md b/1-js/07-object-inheritance/08-class-patterns/2-rewrite-to-prototypes/solution.md similarity index 100% rename from 1-js/9-object-inheritance/08-class-patterns/2-rewrite-to-prototypes/solution.md rename to 1-js/07-object-inheritance/08-class-patterns/2-rewrite-to-prototypes/solution.md diff --git a/1-js/9-object-inheritance/08-class-patterns/2-rewrite-to-prototypes/solution.view/clock.js b/1-js/07-object-inheritance/08-class-patterns/2-rewrite-to-prototypes/solution.view/clock.js similarity index 100% rename from 1-js/9-object-inheritance/08-class-patterns/2-rewrite-to-prototypes/solution.view/clock.js rename to 1-js/07-object-inheritance/08-class-patterns/2-rewrite-to-prototypes/solution.view/clock.js diff --git a/1-js/9-object-inheritance/08-class-patterns/2-rewrite-to-prototypes/solution.view/index.html b/1-js/07-object-inheritance/08-class-patterns/2-rewrite-to-prototypes/solution.view/index.html similarity index 100% rename from 1-js/9-object-inheritance/08-class-patterns/2-rewrite-to-prototypes/solution.view/index.html rename to 1-js/07-object-inheritance/08-class-patterns/2-rewrite-to-prototypes/solution.view/index.html diff --git a/1-js/9-object-inheritance/08-class-patterns/2-rewrite-to-prototypes/source.view/clock.js b/1-js/07-object-inheritance/08-class-patterns/2-rewrite-to-prototypes/source.view/clock.js similarity index 100% rename from 1-js/9-object-inheritance/08-class-patterns/2-rewrite-to-prototypes/source.view/clock.js rename to 1-js/07-object-inheritance/08-class-patterns/2-rewrite-to-prototypes/source.view/clock.js diff --git a/1-js/9-object-inheritance/08-class-patterns/2-rewrite-to-prototypes/source.view/index.html b/1-js/07-object-inheritance/08-class-patterns/2-rewrite-to-prototypes/source.view/index.html similarity index 100% rename from 1-js/9-object-inheritance/08-class-patterns/2-rewrite-to-prototypes/source.view/index.html rename to 1-js/07-object-inheritance/08-class-patterns/2-rewrite-to-prototypes/source.view/index.html diff --git a/1-js/9-object-inheritance/08-class-patterns/2-rewrite-to-prototypes/task.md b/1-js/07-object-inheritance/08-class-patterns/2-rewrite-to-prototypes/task.md similarity index 100% rename from 1-js/9-object-inheritance/08-class-patterns/2-rewrite-to-prototypes/task.md rename to 1-js/07-object-inheritance/08-class-patterns/2-rewrite-to-prototypes/task.md diff --git a/1-js/9-object-inheritance/08-class-patterns/article.md b/1-js/07-object-inheritance/08-class-patterns/article.md similarity index 73% rename from 1-js/9-object-inheritance/08-class-patterns/article.md rename to 1-js/07-object-inheritance/08-class-patterns/article.md index 307f735e..e379d560 100644 --- a/1-js/9-object-inheritance/08-class-patterns/article.md +++ b/1-js/07-object-inheritance/08-class-patterns/article.md @@ -5,11 +5,11 @@ In object-oriented programming, a *class* is an extensible program-code-template for creating objects, providing initial values for state (member variables) and implementations of behavior (member functions or methods). ``` -There's a special syntax construct and a keyword `class` in JavaScript. But before turning to it, we should consider that the term "class" comes the theory of OOP. The definition is cited above. +There's a special syntax construct and a keyword `class` in JavaScript. But before studying it, we should consider that the term "class" comes the theory of object-oriented programming. The definition is cited above, and it's language-independant. -In JavaScript there are several well-known programming patterns to make classes even without using the `class` construct. And here we'll talk about them first. +In JavaScript there are several well-known programming patterns to make classes even without using the `class` keyword. And here we'll talk about them first. -The `class` construct will be described in the next chapter as a "syntax sugar" for things that we're going to study here. +The `class` construct will be described in the next chapter, but in Javascript it's a "syntax sugar" and an extension of one of the patterns that we'll study here. [cut] @@ -37,7 +37,7 @@ It follows all parts of the definition: This is called *functional class pattern*. -In the functional class pattern, variables and functions inside `User`, that are not assigned to `this`, are visible from inside, but not accessible by the outer code. +In the functional class pattern, local variables and nested functions inside `User`, that are not assigned to `this`, are visible from inside, but not accessible by the outer code. So we can easily add internal functions and variables, like `calcAge()` here: @@ -60,7 +60,7 @@ let user = new User("John", new Date(2000,0,1)); user.sayHi(); // John ``` -Variables `name`, `birthday` and the function `calcAge()` are internal, *private* to the object. They are only visible from inside of it. The external code that creates the `user` only can see a *public* method `sayHi`. +In this code variables `name`, `birthday` and the function `calcAge()` are internal, *private* to the object. They are only visible from inside of it. The external code that creates the `user` only can see a *public* method `sayHi`. In works, because functional classes provide a shared lexical environment (of `User`) for private variables and methods. @@ -112,7 +112,9 @@ So the prototypal pattern is more memory-efficient. ## Prototype-based inheritance for classes -Let's say we have two prototype-based classes: +Let's say we have two prototype-based classes. + +`Rabbit`: ```js function Rabbit(name) { @@ -128,7 +130,7 @@ let rabbit = new Rabbit("My rabbit"); ![](rabbit-animal-independent-1.png) -And: +...And `Animal`: ```js function Animal(name) { @@ -146,7 +148,7 @@ let animal = new Animal("My animal"); Right now they are fully independent. -But naturally we'd like `Rabbit` to inherit from `Animal`. In other words, rabbits should be based on animals, and extend them with methods of their own. +But naturally `Rabbit` is a "subtype" of `Animal`. In other words, rabbits should be based on animals, have access to methods of `Animal` and extend them with its own methods. What does it mean in the language on prototypes? @@ -164,6 +166,7 @@ function Animal(name) { this.name = name; } +// All animals can eat, right? Animal.prototype.eat = function() { alert(this.name + ' eats.'); }; @@ -182,8 +185,10 @@ Rabbit.prototype.jump = function() { Rabbit.prototype.__proto__ = Animal.prototype; // (*) */!* -let rabbit = new Rabbit("White Rabbit") -rabbit.eat(); +let rabbit = new Rabbit("White Rabbit"); +*!* +rabbit.eat(); // rabbits can eat too +*/!* rabbit.jump(); ``` @@ -193,6 +198,12 @@ Here's what the code does: ![](class-inheritance-rabbit-animal-2.png) -## Summary [todo] +## Summary -One of problems is lots of words, for every method we write "Rabbit.prototype.method = ..." Classes syntax is sugar fixes that. +The term "class" comes from the object-oriented programming. In Javascript it usually means the functional class pattern or the prototypal pattern. The prototypal pattern is more powerful and memory-efficient, so it's recommended to stick to it. + +According to the prototypal pattern: +1. Methods are stored in `Class.prototype`. +2. Prototypes inherit from each other. + +In the next chapter we'll study `class` keyword and construct. It allows to write prototypal classes shorter and provides some additional benefits. diff --git a/1-js/9-object-inheritance/08-class-patterns/class-inheritance-rabbit-animal-2.png b/1-js/07-object-inheritance/08-class-patterns/class-inheritance-rabbit-animal-2.png similarity index 100% rename from 1-js/9-object-inheritance/08-class-patterns/class-inheritance-rabbit-animal-2.png rename to 1-js/07-object-inheritance/08-class-patterns/class-inheritance-rabbit-animal-2.png diff --git a/1-js/9-object-inheritance/08-class-patterns/class-inheritance-rabbit-animal-2@2x.png b/1-js/07-object-inheritance/08-class-patterns/class-inheritance-rabbit-animal-2@2x.png similarity index 100% rename from 1-js/9-object-inheritance/08-class-patterns/class-inheritance-rabbit-animal-2@2x.png rename to 1-js/07-object-inheritance/08-class-patterns/class-inheritance-rabbit-animal-2@2x.png diff --git a/1-js/9-object-inheritance/08-class-patterns/class-inheritance-rabbit-animal.png b/1-js/07-object-inheritance/08-class-patterns/class-inheritance-rabbit-animal.png similarity index 100% rename from 1-js/9-object-inheritance/08-class-patterns/class-inheritance-rabbit-animal.png rename to 1-js/07-object-inheritance/08-class-patterns/class-inheritance-rabbit-animal.png diff --git a/1-js/9-object-inheritance/08-class-patterns/class-inheritance-rabbit-animal@2x.png b/1-js/07-object-inheritance/08-class-patterns/class-inheritance-rabbit-animal@2x.png similarity index 100% rename from 1-js/9-object-inheritance/08-class-patterns/class-inheritance-rabbit-animal@2x.png rename to 1-js/07-object-inheritance/08-class-patterns/class-inheritance-rabbit-animal@2x.png diff --git a/1-js/9-object-inheritance/08-class-patterns/rabbit-animal-independent-1.png b/1-js/07-object-inheritance/08-class-patterns/rabbit-animal-independent-1.png similarity index 100% rename from 1-js/9-object-inheritance/08-class-patterns/rabbit-animal-independent-1.png rename to 1-js/07-object-inheritance/08-class-patterns/rabbit-animal-independent-1.png diff --git a/1-js/9-object-inheritance/08-class-patterns/rabbit-animal-independent-1@2x.png b/1-js/07-object-inheritance/08-class-patterns/rabbit-animal-independent-1@2x.png similarity index 100% rename from 1-js/9-object-inheritance/08-class-patterns/rabbit-animal-independent-1@2x.png rename to 1-js/07-object-inheritance/08-class-patterns/rabbit-animal-independent-1@2x.png diff --git a/1-js/9-object-inheritance/08-class-patterns/rabbit-animal-independent-2.png b/1-js/07-object-inheritance/08-class-patterns/rabbit-animal-independent-2.png similarity index 100% rename from 1-js/9-object-inheritance/08-class-patterns/rabbit-animal-independent-2.png rename to 1-js/07-object-inheritance/08-class-patterns/rabbit-animal-independent-2.png diff --git a/1-js/9-object-inheritance/08-class-patterns/rabbit-animal-independent-2@2x.png b/1-js/07-object-inheritance/08-class-patterns/rabbit-animal-independent-2@2x.png similarity index 100% rename from 1-js/9-object-inheritance/08-class-patterns/rabbit-animal-independent-2@2x.png rename to 1-js/07-object-inheritance/08-class-patterns/rabbit-animal-independent-2@2x.png diff --git a/1-js/9-object-inheritance/09-class/1-rewrite-to-class/solution.md b/1-js/07-object-inheritance/09-class/1-rewrite-to-class/solution.md similarity index 100% rename from 1-js/9-object-inheritance/09-class/1-rewrite-to-class/solution.md rename to 1-js/07-object-inheritance/09-class/1-rewrite-to-class/solution.md diff --git a/1-js/9-object-inheritance/09-class/1-rewrite-to-class/solution.view/clock.js b/1-js/07-object-inheritance/09-class/1-rewrite-to-class/solution.view/clock.js similarity index 100% rename from 1-js/9-object-inheritance/09-class/1-rewrite-to-class/solution.view/clock.js rename to 1-js/07-object-inheritance/09-class/1-rewrite-to-class/solution.view/clock.js diff --git a/1-js/9-object-inheritance/09-class/1-rewrite-to-class/solution.view/index.html b/1-js/07-object-inheritance/09-class/1-rewrite-to-class/solution.view/index.html similarity index 100% rename from 1-js/9-object-inheritance/09-class/1-rewrite-to-class/solution.view/index.html rename to 1-js/07-object-inheritance/09-class/1-rewrite-to-class/solution.view/index.html diff --git a/1-js/9-object-inheritance/09-class/1-rewrite-to-class/source.view/clock.js b/1-js/07-object-inheritance/09-class/1-rewrite-to-class/source.view/clock.js similarity index 100% rename from 1-js/9-object-inheritance/09-class/1-rewrite-to-class/source.view/clock.js rename to 1-js/07-object-inheritance/09-class/1-rewrite-to-class/source.view/clock.js diff --git a/1-js/9-object-inheritance/09-class/1-rewrite-to-class/source.view/index.html b/1-js/07-object-inheritance/09-class/1-rewrite-to-class/source.view/index.html similarity index 100% rename from 1-js/9-object-inheritance/09-class/1-rewrite-to-class/source.view/index.html rename to 1-js/07-object-inheritance/09-class/1-rewrite-to-class/source.view/index.html diff --git a/1-js/9-object-inheritance/09-class/1-rewrite-to-class/task.md b/1-js/07-object-inheritance/09-class/1-rewrite-to-class/task.md similarity index 100% rename from 1-js/9-object-inheritance/09-class/1-rewrite-to-class/task.md rename to 1-js/07-object-inheritance/09-class/1-rewrite-to-class/task.md diff --git a/1-js/9-object-inheritance/09-class/animal-rabbit-extends.png b/1-js/07-object-inheritance/09-class/animal-rabbit-extends.png similarity index 100% rename from 1-js/9-object-inheritance/09-class/animal-rabbit-extends.png rename to 1-js/07-object-inheritance/09-class/animal-rabbit-extends.png diff --git a/1-js/9-object-inheritance/09-class/animal-rabbit-extends@2x.png b/1-js/07-object-inheritance/09-class/animal-rabbit-extends@2x.png similarity index 100% rename from 1-js/9-object-inheritance/09-class/animal-rabbit-extends@2x.png rename to 1-js/07-object-inheritance/09-class/animal-rabbit-extends@2x.png diff --git a/1-js/9-object-inheritance/09-class/article.md b/1-js/07-object-inheritance/09-class/article.md similarity index 98% rename from 1-js/9-object-inheritance/09-class/article.md rename to 1-js/07-object-inheritance/09-class/article.md index c61de85b..e8943355 100644 --- a/1-js/9-object-inheritance/09-class/article.md +++ b/1-js/07-object-inheritance/09-class/article.md @@ -7,7 +7,7 @@ The "class" construct allows to define prototype-based classes with a clean, nic ## The "class" syntax -The `class` syntax is versatile, so we'll start from a simple example first. +The `class` syntax is versatile, we'll start from a simple example first. Here's a prototype-based class `User`: diff --git a/1-js/9-object-inheritance/09-class/class-user.png b/1-js/07-object-inheritance/09-class/class-user.png similarity index 100% rename from 1-js/9-object-inheritance/09-class/class-user.png rename to 1-js/07-object-inheritance/09-class/class-user.png diff --git a/1-js/9-object-inheritance/09-class/class-user@2x.png b/1-js/07-object-inheritance/09-class/class-user@2x.png similarity index 100% rename from 1-js/9-object-inheritance/09-class/class-user@2x.png rename to 1-js/07-object-inheritance/09-class/class-user@2x.png diff --git a/1-js/07-object-inheritance/10-class-inheritance/1-class-constructor-error/solution.md b/1-js/07-object-inheritance/10-class-inheritance/1-class-constructor-error/solution.md new file mode 100644 index 00000000..4711e482 --- /dev/null +++ b/1-js/07-object-inheritance/10-class-inheritance/1-class-constructor-error/solution.md @@ -0,0 +1,27 @@ +That's because the child constructor must call `super()`. + +Here's the corrected code: + +```js run +class Animal { + + constructor(name) { + this.name = name; + } + +} + +class Rabbit extends Animal { + constructor(name) { + *!* + super(name); + */!* + this.created = Date.now(); + } +} + +*!* +let rabbit = new Rabbit("White Rabbit"); // ok now +*/!* +alert(rabbit.name); // White Rabbit +``` diff --git a/1-js/07-object-inheritance/10-class-inheritance/1-class-constructor-error/task.md b/1-js/07-object-inheritance/10-class-inheritance/1-class-constructor-error/task.md new file mode 100644 index 00000000..380a4720 --- /dev/null +++ b/1-js/07-object-inheritance/10-class-inheritance/1-class-constructor-error/task.md @@ -0,0 +1,30 @@ +importance: 5 + +--- + +# Error creating an instance + +Here's the code with `Rabbit` extending `Animal`. + +Unfortunately, `Rabbit` objects can't be created. What's wrong? Fix it. +```js run +class Animal { + + constructor(name) { + this.name = name; + } + +} + +class Rabbit extends Animal { + constructor(name) { + this.name = name; + this.created = Date.now(); + } +} + +*!* +let rabbit = new Rabbit("White Rabbit"); // Error: this is not defined +*/!* +alert(rabbit.name); +``` diff --git a/1-js/9-object-inheritance/10-class-inheritance/1-clock-class-extended/solution.md b/1-js/07-object-inheritance/10-class-inheritance/2-clock-class-extended/solution.md similarity index 100% rename from 1-js/9-object-inheritance/10-class-inheritance/1-clock-class-extended/solution.md rename to 1-js/07-object-inheritance/10-class-inheritance/2-clock-class-extended/solution.md diff --git a/1-js/9-object-inheritance/10-class-inheritance/1-clock-class-extended/solution.view/clock.js b/1-js/07-object-inheritance/10-class-inheritance/2-clock-class-extended/solution.view/clock.js similarity index 100% rename from 1-js/9-object-inheritance/10-class-inheritance/1-clock-class-extended/solution.view/clock.js rename to 1-js/07-object-inheritance/10-class-inheritance/2-clock-class-extended/solution.view/clock.js diff --git a/1-js/9-object-inheritance/10-class-inheritance/1-clock-class-extended/solution.view/extended-clock.js b/1-js/07-object-inheritance/10-class-inheritance/2-clock-class-extended/solution.view/extended-clock.js similarity index 100% rename from 1-js/9-object-inheritance/10-class-inheritance/1-clock-class-extended/solution.view/extended-clock.js rename to 1-js/07-object-inheritance/10-class-inheritance/2-clock-class-extended/solution.view/extended-clock.js diff --git a/1-js/9-object-inheritance/10-class-inheritance/1-clock-class-extended/solution.view/index.html b/1-js/07-object-inheritance/10-class-inheritance/2-clock-class-extended/solution.view/index.html similarity index 100% rename from 1-js/9-object-inheritance/10-class-inheritance/1-clock-class-extended/solution.view/index.html rename to 1-js/07-object-inheritance/10-class-inheritance/2-clock-class-extended/solution.view/index.html diff --git a/1-js/9-object-inheritance/10-class-inheritance/1-clock-class-extended/source.view/clock.js b/1-js/07-object-inheritance/10-class-inheritance/2-clock-class-extended/source.view/clock.js similarity index 100% rename from 1-js/9-object-inheritance/10-class-inheritance/1-clock-class-extended/source.view/clock.js rename to 1-js/07-object-inheritance/10-class-inheritance/2-clock-class-extended/source.view/clock.js diff --git a/1-js/9-object-inheritance/10-class-inheritance/1-clock-class-extended/source.view/index.html b/1-js/07-object-inheritance/10-class-inheritance/2-clock-class-extended/source.view/index.html similarity index 100% rename from 1-js/9-object-inheritance/10-class-inheritance/1-clock-class-extended/source.view/index.html rename to 1-js/07-object-inheritance/10-class-inheritance/2-clock-class-extended/source.view/index.html diff --git a/1-js/9-object-inheritance/10-class-inheritance/1-clock-class-extended/task.md b/1-js/07-object-inheritance/10-class-inheritance/2-clock-class-extended/task.md similarity index 100% rename from 1-js/9-object-inheritance/10-class-inheritance/1-clock-class-extended/task.md rename to 1-js/07-object-inheritance/10-class-inheritance/2-clock-class-extended/task.md diff --git a/1-js/9-object-inheritance/10-class-inheritance/animal-rabbit-static.png b/1-js/07-object-inheritance/10-class-inheritance/animal-rabbit-static.png similarity index 100% rename from 1-js/9-object-inheritance/10-class-inheritance/animal-rabbit-static.png rename to 1-js/07-object-inheritance/10-class-inheritance/animal-rabbit-static.png diff --git a/1-js/9-object-inheritance/10-class-inheritance/animal-rabbit-static@2x.png b/1-js/07-object-inheritance/10-class-inheritance/animal-rabbit-static@2x.png similarity index 100% rename from 1-js/9-object-inheritance/10-class-inheritance/animal-rabbit-static@2x.png rename to 1-js/07-object-inheritance/10-class-inheritance/animal-rabbit-static@2x.png diff --git a/1-js/9-object-inheritance/10-class-inheritance/article.md b/1-js/07-object-inheritance/10-class-inheritance/article.md similarity index 100% rename from 1-js/9-object-inheritance/10-class-inheritance/article.md rename to 1-js/07-object-inheritance/10-class-inheritance/article.md diff --git a/1-js/07-object-inheritance/10-class-inheritance/class-inheritance-array-object.png b/1-js/07-object-inheritance/10-class-inheritance/class-inheritance-array-object.png new file mode 100644 index 00000000..c5d71263 Binary files /dev/null and b/1-js/07-object-inheritance/10-class-inheritance/class-inheritance-array-object.png differ diff --git a/1-js/07-object-inheritance/10-class-inheritance/class-inheritance-array-object@2x.png b/1-js/07-object-inheritance/10-class-inheritance/class-inheritance-array-object@2x.png new file mode 100644 index 00000000..edc4e841 Binary files /dev/null and b/1-js/07-object-inheritance/10-class-inheritance/class-inheritance-array-object@2x.png differ diff --git a/1-js/9-object-inheritance/10-class-inheritance/class-inheritance-rabbit-animal.png b/1-js/07-object-inheritance/10-class-inheritance/class-inheritance-rabbit-animal.png similarity index 100% rename from 1-js/9-object-inheritance/10-class-inheritance/class-inheritance-rabbit-animal.png rename to 1-js/07-object-inheritance/10-class-inheritance/class-inheritance-rabbit-animal.png diff --git a/1-js/9-object-inheritance/10-class-inheritance/class-inheritance-rabbit-animal@2x.png b/1-js/07-object-inheritance/10-class-inheritance/class-inheritance-rabbit-animal@2x.png similarity index 100% rename from 1-js/9-object-inheritance/10-class-inheritance/class-inheritance-rabbit-animal@2x.png rename to 1-js/07-object-inheritance/10-class-inheritance/class-inheritance-rabbit-animal@2x.png diff --git a/1-js/9-object-inheritance/10-class-inheritance/class-inheritance-rabbit-run-animal.png b/1-js/07-object-inheritance/10-class-inheritance/class-inheritance-rabbit-run-animal.png similarity index 100% rename from 1-js/9-object-inheritance/10-class-inheritance/class-inheritance-rabbit-run-animal.png rename to 1-js/07-object-inheritance/10-class-inheritance/class-inheritance-rabbit-run-animal.png diff --git a/1-js/9-object-inheritance/10-class-inheritance/class-inheritance-rabbit-run-animal@2x.png b/1-js/07-object-inheritance/10-class-inheritance/class-inheritance-rabbit-run-animal@2x.png similarity index 100% rename from 1-js/9-object-inheritance/10-class-inheritance/class-inheritance-rabbit-run-animal@2x.png rename to 1-js/07-object-inheritance/10-class-inheritance/class-inheritance-rabbit-run-animal@2x.png diff --git a/1-js/9-object-inheritance/10-class-inheritance/object-date-inheritance.png b/1-js/07-object-inheritance/10-class-inheritance/object-date-inheritance.png similarity index 100% rename from 1-js/9-object-inheritance/10-class-inheritance/object-date-inheritance.png rename to 1-js/07-object-inheritance/10-class-inheritance/object-date-inheritance.png diff --git a/1-js/9-object-inheritance/10-class-inheritance/object-date-inheritance@2x.png b/1-js/07-object-inheritance/10-class-inheritance/object-date-inheritance@2x.png similarity index 100% rename from 1-js/9-object-inheritance/10-class-inheritance/object-date-inheritance@2x.png rename to 1-js/07-object-inheritance/10-class-inheritance/object-date-inheritance@2x.png diff --git a/1-js/9-object-inheritance/10-class-inheritance/this-super-loop.png b/1-js/07-object-inheritance/10-class-inheritance/this-super-loop.png similarity index 100% rename from 1-js/9-object-inheritance/10-class-inheritance/this-super-loop.png rename to 1-js/07-object-inheritance/10-class-inheritance/this-super-loop.png diff --git a/1-js/9-object-inheritance/10-class-inheritance/this-super-loop@2x.png b/1-js/07-object-inheritance/10-class-inheritance/this-super-loop@2x.png similarity index 100% rename from 1-js/9-object-inheritance/10-class-inheritance/this-super-loop@2x.png rename to 1-js/07-object-inheritance/10-class-inheritance/this-super-loop@2x.png diff --git a/1-js/9-object-inheritance/11-instanceof/1-strange-instanceof/solution.md b/1-js/07-object-inheritance/11-instanceof/1-strange-instanceof/solution.md similarity index 100% rename from 1-js/9-object-inheritance/11-instanceof/1-strange-instanceof/solution.md rename to 1-js/07-object-inheritance/11-instanceof/1-strange-instanceof/solution.md diff --git a/1-js/9-object-inheritance/11-instanceof/1-strange-instanceof/task.md b/1-js/07-object-inheritance/11-instanceof/1-strange-instanceof/task.md similarity index 100% rename from 1-js/9-object-inheritance/11-instanceof/1-strange-instanceof/task.md rename to 1-js/07-object-inheritance/11-instanceof/1-strange-instanceof/task.md diff --git a/1-js/9-object-inheritance/11-instanceof/article.md b/1-js/07-object-inheritance/11-instanceof/article.md similarity index 96% rename from 1-js/9-object-inheritance/11-instanceof/article.md rename to 1-js/07-object-inheritance/11-instanceof/article.md index 392d0001..76538500 100644 --- a/1-js/9-object-inheritance/11-instanceof/article.md +++ b/1-js/07-object-inheritance/11-instanceof/article.md @@ -92,9 +92,13 @@ The algorithm of `obj instanceof Class` works roughly as follows: // rabbit.__proto__.__proto__ == Animal.prototype (match!) ``` +Here's the illustration of what `rabbit instanceof Animal` compares with `Animal.prototype`: + +![](instanceof.png) + By the way, there's also a method [objA.isPrototypeOf(objB)](mdn:js/object/isPrototypeOf), that returns `true` if `objA` is somewhere in the chain of prototypes for `objB`. So the test of `obj instanceof Class` can be rephrased as `Class.prototype.isPrototypeOf(obj)`. -Please note: that's funny, but the `Class` constructor itself does not participate in the check! Only the chain of prototypes and `Class.prototype` matters. +That's funny, but the `Class` constructor itself does not participate in the check! Only the chain of prototypes and `Class.prototype` matters. That can lead to interesting consequences when `prototype` is changed. diff --git a/1-js/07-object-inheritance/11-instanceof/instanceof.png b/1-js/07-object-inheritance/11-instanceof/instanceof.png new file mode 100644 index 00000000..85aa9a55 Binary files /dev/null and b/1-js/07-object-inheritance/11-instanceof/instanceof.png differ diff --git a/1-js/07-object-inheritance/11-instanceof/instanceof@2x.png b/1-js/07-object-inheritance/11-instanceof/instanceof@2x.png new file mode 100644 index 00000000..fba77122 Binary files /dev/null and b/1-js/07-object-inheritance/11-instanceof/instanceof@2x.png differ diff --git a/1-js/9-object-inheritance/13-mixins/article.md b/1-js/07-object-inheritance/13-mixins/article.md similarity index 66% rename from 1-js/9-object-inheritance/13-mixins/article.md rename to 1-js/07-object-inheritance/13-mixins/article.md index 7b6c5c29..7d194b59 100644 --- a/1-js/9-object-inheritance/13-mixins/article.md +++ b/1-js/07-object-inheritance/13-mixins/article.md @@ -4,16 +4,17 @@ In JavaScript we can only inherit from a single object. There can be only one `[ But sometimes we need such kind of thing. For instance, we have a code that implements events exchange or templating, and we'd like to be able to add these capabilities to any class easily. -What can help here is *mixins* or *traits*. +What can help here is *mixins*. -A *mixin* is a class or an object that implements a certain behavior. We do not use it alone, but rather use to complement other classes. -[cut] +As [defined in Wikipedia](https://en.wikipedia.org/wiki/Mixin), a *mixin* is a class that contains methods for use by other classes without having to be the parent class of those other classes. + +In other words, a *mixin* is a class that implements a certain behavior. But we do not use it alone, we use it to add the behavior to other classes. ## A mixin example -The simplest way to make a mixin -- is to make an object with useful methods, that we can just copy into the prototype. +The simplest way to make a mixin in Javascript -- is to make an object with useful methods, that we can just copy into the prototype. -For instance: +For instance here the mixin `sayHiMixin` is used to add some "speech" for `User`: ```js run *!* @@ -44,7 +45,9 @@ Object.assign(User.prototype, sayHiMixin); new User("Dude").sayHi(); // Hi Dude! ``` -Mixins also can inherit from each other. +There's no inheritance, there's a simple method copying. So `User` may extend some other class and also include the mixin to "mix-in" the additional methods. + +Mixins also can also make use of inheritance. For instance, here `sayHiMixin` inherits from `sayMixin`: @@ -56,11 +59,13 @@ let sayMixin = { }; let sayHiMixin = { - __proto__: sayMixin, // can use other prototype-setting methods instead -*!* - // call parent method -*/!* + // can use any way of prototype setting here + __proto__: sayMixin, + sayHi() { + *!* + // call parent method + */!* super.say("Hello " + this.name); }, sayBye() { @@ -81,9 +86,11 @@ Object.assign(User.prototype, sayHiMixin); new User("Dude").sayHi(); // Hi Dude! ``` -Please note that the call to `super.say()` from a mixin looks for the method in the prototype of that mixin, not the class. +Please note that the call to the parent method `super.say()` from `sayHiMixin` looks for the method in the prototype of that mixin, not the class. -That's because methods from `sayHiMixin` have `[[HomeObject]]` set to `sayHiMixin`. So `super` actually means `sayHiMixin.__proto__`, that is `sayMixin`. +![](mixin-inheritance.png) + +That's because methods from `sayHiMixin` have `[[HomeObject]]` set to it. So `super` actually means `sayHiMixin.__proto__`, not `User.__proto__`. ## EventMixin @@ -173,17 +180,20 @@ let menu = new Menu(); menu.on("select", value => alert("Value selected: " + value)); */!* -// the choice has happened! +// triggers the event => shows Value selected: 123 menu.choose("123"); // value selected ``` Now if we have the code interested to react on user selection, we can bind it with `menu.on(...)`. -And the mixin can be added to as many classes as we'd like. +And the `eventMixin` can add such behavior to as many classes as we'd like, without interfering with the inheritance chain. -## Summary [todo] +## Summary -- Примесь -- объект, содержащий методы и свойства для реализации конкретного функционала. -Возможны вариации этого приёма проектирования. Например, примесь может предусматривать конструктор, который должен запускаться в конструкторе объекта. Но как правило просто набора методов хватает. -- Для добавления примеси в класс -- её просто "подмешивают" в прототип. -- "Подмешать" можно сколько угодно примесей, но если имена методов в разных примесях совпадают, то возможны конфликты. Их уже разрешать -- разработчику. Например, можно заменить конфликтующий метод на свой, который будет решать несколько задач сразу. Конфликты при грамотно оформленных примесях возникают редко. +*Mixin* -- is a generic object-oriented programming term: a class that contains methods for other classes. + +In Javascript that can be implemented as copying them into the prototype. + +We can use mixins as a way to augment a class by multiple behaviors like event-handling that we overlooked above. + +Mixins may become a point of conflict if they occasionally overwrite native class methods. So generally one should think well about the naming for a mixin, to minimalize such possibility. diff --git a/1-js/9-object-inheritance/13-mixins/head.html b/1-js/07-object-inheritance/13-mixins/head.html similarity index 100% rename from 1-js/9-object-inheritance/13-mixins/head.html rename to 1-js/07-object-inheritance/13-mixins/head.html diff --git a/1-js/07-object-inheritance/13-mixins/mixin-inheritance.png b/1-js/07-object-inheritance/13-mixins/mixin-inheritance.png new file mode 100644 index 00000000..7cc65503 Binary files /dev/null and b/1-js/07-object-inheritance/13-mixins/mixin-inheritance.png differ diff --git a/1-js/07-object-inheritance/13-mixins/mixin-inheritance@2x.png b/1-js/07-object-inheritance/13-mixins/mixin-inheritance@2x.png new file mode 100644 index 00000000..f53ecf68 Binary files /dev/null and b/1-js/07-object-inheritance/13-mixins/mixin-inheritance@2x.png differ diff --git a/1-js/9-object-inheritance/index.md b/1-js/07-object-inheritance/index.md similarity index 100% rename from 1-js/9-object-inheritance/index.md rename to 1-js/07-object-inheritance/index.md diff --git a/1-js/08-error-handling/1-try-catch/1-finally-or-code-after/solution.md b/1-js/08-error-handling/1-try-catch/1-finally-or-code-after/solution.md new file mode 100644 index 00000000..05ba72e0 --- /dev/null +++ b/1-js/08-error-handling/1-try-catch/1-finally-or-code-after/solution.md @@ -0,0 +1,47 @@ +The difference becomes obvious when we look at the code inside a function. + +The behavior is different if there's a "jump out" of `try..catch`. + +For instance, when there's a `return` inside `try..catch`. The `finally` clause works in case of *any* exit from `try..catch`, even via the `return` statement: right after `try..catch` is done, but before the calling code gets the control. + +```js run +function f() { + try { + alert('start'); +*!* + return "result"; +*/!* + } catch (e) { + /// ... + } finally { + alert('cleanup!'); + } +} + +f(); // cleanup! +``` + +...Or when there's a `throw`, like here: + +```js run +function f() { + try { + alert('start'); + throw new Error("an error"); + } catch (e) { + // ... + if("can't handle the error") { +*!* + throw e; +*/!* + } + + } finally { + alert('cleanup!') + } +} + +f(); // cleanup! +``` + +It's `finally` that guarantees the cleanup here. If we just put the code at the end of `f`, it wouldn't run. diff --git a/1-js/08-error-handling/1-try-catch/1-finally-or-code-after/task.md b/1-js/08-error-handling/1-try-catch/1-finally-or-code-after/task.md new file mode 100644 index 00000000..e8468734 --- /dev/null +++ b/1-js/08-error-handling/1-try-catch/1-finally-or-code-after/task.md @@ -0,0 +1,38 @@ +importance: 5 + +--- + +# Finally or just the code? + +Compare the two code fragments. + +1. The first one uses `finally` to execute the code after `try..catch`: + + ```js + try { + work work + } catch (e) { + handle errors + } finally { + *!* + cleanup the working space + */!* + } + ``` +2. The second fragment puts the cleaning right after `try..catch`: + + ```js + try { + work work + } catch (e) { + handle errors + } + + *!* + cleanup the working space + */!* + ``` + +We definitely need the cleanup after the work has started, doesn't matter if there was an error or not. + +Is there an advantage here in using `finally` or both code fragments are equal? If there is such an advantage, then give an example when it matters. diff --git a/1-js/7-advanced-syntax/4-try-catch/article.md b/1-js/08-error-handling/1-try-catch/article.md similarity index 66% rename from 1-js/7-advanced-syntax/4-try-catch/article.md rename to 1-js/08-error-handling/1-try-catch/article.md index 28696789..41503f06 100644 --- a/1-js/7-advanced-syntax/4-try-catch/article.md +++ b/1-js/08-error-handling/1-try-catch/article.md @@ -77,7 +77,7 @@ Let's see the examples. Please note that if the code structure is violated, like a figure bracket is left unclosed, then `try..catch` can't help. Such errors are fatal, the engine just cannot run the code. -There is a better term for errors that we are catching: "an exceptional situation" or just "an exception". It's much more precise, meaning exactly the situation when a already-running and well-formed code meets a problem. +There is a better term for errors that we are catching: "an exceptional situation" or just "an exception". It's much more precise, meaning exactly the situation when a already-running and well-formed code meets a problem. For all built-in errors, the error object inside `catch` block has two main properties: @@ -90,7 +90,7 @@ For all built-in errors, the error object inside `catch` block has two main prop There are other non-standard properties in most environments. One of most widely used and supported everywhere is: `stack` -: Current call stack, a string with information about the sequence of nested calls that led to the error. Used for debugging purposes. +: Current call stack: a string with information about the sequence of nested calls that led to the error. Used for debugging purposes. ````warn header="`try..catch` only works in synchronous code" @@ -99,7 +99,7 @@ If an exception happens in the future code, like those inside `setTimeout`, then ```js run try { setTimeout(function() { - blablabla; // script will die here + noSuchVariable; // script will die here }, 1000); } catch (e) { alert( "won't work" ); @@ -111,8 +111,25 @@ That's because at the moment of running the function from `setTimeout`, the curr To catch an exception inside a scheduled function, `try..catch` must be inside that function. ```` +````warn header="`try..catch` only works for runtime errors" +For `try..catch` to work, the code must be runnable. In other words, it should be valid Javascript. -## Using try..catch +It won't work if the code is syntactically wrong, for instance it has unmatched figure brackets: + +```js run +try { + {{{{{{{{{{{{ +} catch(e) { + alert("The engine can't understand this code, it's invalid"); +} +``` + +The Javascript engine first reads the code, and then runs it. The errors that occur on the reading phrase are called "parse-time" errors and are unrecoverable (from inside that code). That's because the engine can't understand the code as a whole, and `try..catch` is a part of it. + +So, `try..catch` can only handle errors that occur in the valid code. Such errors are called "runtime" errors. +```` + +## Using "try..catch" Let's explore a real-life use case of `try..catch`. @@ -145,7 +162,7 @@ And people really really don't like when something "just dies" without any error Let's use `try..catch` to handle the error: ```js run -let json = "{ bad json }"; +let json = "{ bad json }"; try { @@ -233,7 +250,7 @@ try { } ``` -As we can see, that's a `SyntaxError`. +As we can see, that's a `SyntaxError`. ...And in our case, the absense of `name` can be treated as a syntax error also, assuming that users follow a sort of "schema" that requires the existance of `"name"`. @@ -261,7 +278,7 @@ try { In the line `(*)` the `throw` operator generates `SyntaxError` with the given `message`, the same way as Javascript would generate itself. The execution of `try` immediately stops and the control flow jumps into `catch`. -Now `catch` became a single place for all error handling: both for `JSON.parse` and other cases. +Now `catch` became a single place for all error handling: both for `JSON.parse` and other cases. ## Rethrowing @@ -269,7 +286,7 @@ In the example above we implemented error handling for incorrect data. But is it Of course, it is! Normally, a code is a bag with errors. It's typical that even in an open-source utility like `ssh` that is used by millions for decades -- suddenly a crazy bug is discovered that leads to terrible hacks. Not to mention other similar cases. -In our case, `catch` block is meant to process "incorrect data" errors. But right now it catches everything. +In our case, `catch` block is meant to process "incorrect data" errors. But right now it catches everything. For instance, say, we made a programming error, a mistype: @@ -348,7 +365,7 @@ The example below demonstrates how such errors can be caught by one more level o ```js run function readData() { - let json = '{ "age": 30 }'; + let json = '{ "age": 30 }'; try { // ... @@ -376,72 +393,6 @@ try { Here `readData` only knows how to handle `SyntaxError`, while the outer `try..catch` knows how to handle everything. -## Wrapping exceptions - -And now -- the most advanced technique to work with exceptions. It is often used in object-oriented code. - -The purpose of the function `readData` in the code above is -- to "read the data", right? There may occur different kinds of errors in the process, not only `SyntaxError`, but `URIError` (wrong usage of some functions) or network errors, or others. - -The code which calls `readData` wants either a result or the information about the error. - -The important questions it: does it have to know about all possible types of reading errors and catch them? - -Usually, the answer is: "No". - -The outer code wants to be "one level above all that". It wants to have a "data reading error", and why exactly it happened -- is usually irrelevant. Or, even better if there is a way to get such details, but that's rarely needed. - -In our case, when error occurs, we will create our own object `ReadError`, with the proper message. And we'll also keep the original error in its `cause` property, just in case. - -Here you are: - -```js run -function ReadError(message, cause) { - this.message = message; - this.cause = cause; - this.name = 'ReadError'; -} - -function readData() { - let json = '{ bad json }'; - - try { - // ... - JSON.parse(json); - // ... - } catch (e) { - // ... - if (e.name == 'URIError') { - throw new ReadError("URI Error", e); - } else if (e.name == 'SyntaxError') { -*!* - throw new ReadError("Syntax error in the data", e); -*/!* - } else { - throw e; // rethrow - } - } -} - -try { - readData(); -} catch (e) { - if (e.name == 'ReadError') { -*!* - alert( e.message ); - alert( e.cause ); // original error -*/!* - } else { - throw e; - } -} -``` - -The approach is called "wrapping exceptions", because we take "low level exceptions" and "wrap" them into `ReadError` that is more abstract, and probably more convenient to use for the calling code. - -The best thing about it is that we can modify `readData`, catch more low-level errors in the process -- and we will not need to add tests for them in `catch` of the external code. - -The external code does not cares about low-level details. It handles `ReadError`, that's enough. - ## try..catch..finally Wait, that's not all. @@ -485,7 +436,9 @@ The code has two variants: The `finally` clause is often used when we start doing something before `try..catch` and want to finalize it in any case of outcome. -For instance, we want to measure time that a Fibonacci numbers function `fib(n)` takes. But it returns an error for negative or non-integer numbers: +For instance, we want to measure time that a Fibonacci numbers function `fib(n)` takes. Naturally, we can start measuring before it runs and finish afterwards. But what is there's an error during the function call? In particular, the implementation of `fib(n)` in the code below returns an error for negative or non-integer numbers. + +The `finally` clause is a great place to finish the measurements no matter how the function finishes. ```js run let num = +prompt("Enter a positive integer number?", 35) @@ -516,18 +469,21 @@ alert(result || "error occured"); alert( `execution took ${diff}ms` ); ``` -Here `finally` guarantees that the time will be measured in both situations -- in case of a successful execution of `fib` and in case of an error. +Here `finally` guarantees that the time will be measured correctly in both situations -- in case of a successful execution of `fib` and in case of an error in it. You can check that by running the code with `num=35` -- executes normally, `finally` after `try`, and then with `num=-1`, there will be an immediate error, an the execution will take `0ms`. -```smart header="Variables are local to try..catch..finally clauses" -Please note that `result` and `diff` variables are declared *before* `try..catch`. +In other words, there may be two ways to exist from a function: either a `return` or `throw`. The `finally` handles them both. -Otherwise, if `let` is made inside the `{...}` clause, it is only visible inside of it. + +```smart header="Variables are local to try..catch..finally clauses" +Please note that `result` and `diff` variables in the code above are declared *before* `try..catch`. + +Otherwise, if `let` were made inside the `{...}` clause, it would only be visible inside of it. ``` ````smart header="`finally` and `return`" -Finally clause works for *any* exit from `try..catch` including `return`. +Finally clause works for *any* exit from `try..catch`. That includes the `return` directive. In the example below, there's a `return` in `try`. In this case, `finally` is executed just before the control returns to the outer code. @@ -552,7 +508,7 @@ alert( func() ); // first works alert from finally, and then this one ````smart header="`try..finally`" -The `try..finally` construct, without `catch` clause, is used when we don't want or don't know how to handle errors, but want to be sure that processes that we started are finalized. +The `try..finally` construct, without `catch` clause, is also useful. We apply it when we don't want to handle errors right here, but want to be sure that processes that we started are finalized. ```js function func() { @@ -560,21 +516,24 @@ function func() { try { // ... } finally { - // complete that thing + // complete that thing even if all dies } } ``` +In the code above, an error inside `try` always falls out, because there's no `catch`. But `finally` triggers before that. ```` ## Global catch +```warn header="Environment-specific" +The information from this section is not a part of the core Javascript. +``` + Let's imagine we've got a fatal error outside of `try..catch`, and the script died. -Is there a way to react on it? +Is there a way to react on it? We may want to log the error, show something to the user (normally he doesn't see the error message) etc. -There is none in the specification, but environments may provide it. - -Node.JS has [process.on('uncaughtException')](https://nodejs.org/api/process.html#process_event_uncaughtexception) for that. And in the browser we can assign a function to special [window.onerror](mdn:api/GlobalEventHandlers/onerror) property. It will run in case of an uncaught error. +There is none in the specification, but environments usually provide it, because it's really handy. For instance, Node.JS has [process.on('uncaughtException')](https://nodejs.org/api/process.html#process_event_uncaughtexception) for that. And in the browser we can assign a function to special [window.onerror](mdn:api/GlobalEventHandlers/onerror) property. It will run in case of an uncaught error. The syntax: @@ -618,42 +577,33 @@ The role of the global handler is usually not to recover the script execution -- There are also web-services that provide error-logging facilities, like or . They give a script with custom `window.onerror` function, and once inserted into a page, it reports about all errors it gets to their server. Afterwards developers can browse them and get notifications on email about fresh errors. -## Summary [todo] +## Summary -Обработка ошибок -- большая и важная тема. +The `try..catch` construct allows to handle runtime errors. It literally allows to try running the code and catch errors that may occur in it. -В JavaScript для этого предусмотрены: +The syntax is: -- Конструкция `try..catch..finally` -- она позволяет обработать произвольные ошибки в блоке кода. +```js +try { + // run this code +} catch(err) { + // if an error happened, then jump here + // err is the error object +} finally { + // do in any case after try/catch +} +``` - Это удобно в тех случаях, когда проще сделать действие и потом разбираться с результатом, чем долго и нудно проверять, не упадёт ли чего. +There may be no `catch` section or no `finally`, so `try..catch` and `try..finally` are also valid. - Кроме того, иногда проверить просто невозможно, например `JSON.parse(str)` не позволяет "проверить" формат строки перед разбором. В этом случае блок `try..catch` необходим. +Error objects have following properties: - Полный вид конструкции: +- `message` -- the human-readable error message. +- `name` -- the string with error name (error constructor name). +- `stack` (non-standard) -- the stack at the moment of error creation. - ```js - *!*try*/!* { - .. пробуем выполнить код .. - } *!*catch*/!*(e) { - .. перехватываем исключение .. - } *!*finally*/!* { - .. выполняем всегда .. - } - ``` +We can also generate our own errors using the `throw` operator. Technically, the argument of `throw` can be anything, but usually it's an error object inheriting from the built-in `Error` class. More on extending errors in the next chapter. - Возможны также варианты `try..catch` или `try..finally`. -- Оператор `throw err` генерирует свою ошибку, в качестве `err` рекомендуется использовать объекты, совместимые с встроенным типом [Error](http://javascript.ru/Error), содержащие свойства `message` и `name`. - -Кроме того, мы рассмотрели некоторые важные приёмы: - -- Проброс исключения -- `catch(err)` должен обрабатывать только те ошибки, которые мы рассчитываем в нём увидеть, остальные -- пробрасывать дальше через `throw err`. - - Определить, нужная ли это ошибка, можно, например, по свойству `name`. -- Оборачивание исключений -- функция, в процессе работы которой возможны различные виды ошибок, может "обернуть их" в одну общую ошибку, специфичную для её задачи, и уже её пробросить дальше. Чтобы, при необходимости, можно было подробно определить, что произошло, исходную ошибку обычно присваивают в свойство этой, общей. Обычно это нужно для логирования. -- В `window.onerror` можно присвоить функцию, которая выполнится при любой "выпавшей" из скрипта ошибке. Как правило, это используют в информационных целях, например отправляют информацию об ошибке на специальный сервис. - -Later we'll learn more oop and inheritance for errors. - -TODO: try..catch in decorators? If I leave it here. +Rethrowing is a basic pattern of error handling: a `catch` block usually expects and knows how to handle the particular error type, so it should rethrow errors it doesn't know. +Even if we don't have `try..catch`, most environments allow to setup a "global" error handler to catch errors that "fall out". In-browser that's `window.onerror`. diff --git a/1-js/08-error-handling/12-oop-errors/1-format-error/solution.md b/1-js/08-error-handling/12-oop-errors/1-format-error/solution.md new file mode 100644 index 00000000..bb6b74cf --- /dev/null +++ b/1-js/08-error-handling/12-oop-errors/1-format-error/solution.md @@ -0,0 +1,16 @@ +```js run untrusted +class FormatError extends SyntaxError { + constructor(message) { + super(message); + this.name = "FormatError"; + } +} + +let err = new FormatError("formatting error"); + +alert( err.message ); // formatting error +alert( err.name ); // FormatError +alert( err.stack ); // stack + +alert( err instanceof SyntaxError ); // true +``` diff --git a/1-js/08-error-handling/12-oop-errors/1-format-error/task.md b/1-js/08-error-handling/12-oop-errors/1-format-error/task.md new file mode 100644 index 00000000..03532d32 --- /dev/null +++ b/1-js/08-error-handling/12-oop-errors/1-format-error/task.md @@ -0,0 +1,18 @@ +importance: 5 + +--- + +# Inherit from SyntaxError + +Create an error `FormatError` that inherits from `SyntaxError`. + +Usage example: +```js +let err = new FormatError("formatting error"); + +alert( err.message ); // formatting error +alert( err.name ); // FormatError +alert( err.stack ); // stack + +alert( err instanceof SyntaxError ); // true +``` diff --git a/1-js/08-error-handling/12-oop-errors/article.md b/1-js/08-error-handling/12-oop-errors/article.md new file mode 100644 index 00000000..572ecdc6 --- /dev/null +++ b/1-js/08-error-handling/12-oop-errors/article.md @@ -0,0 +1,281 @@ +# Custom errors, extending Error + +When we develop our software, we need our own error classes. For network operations we may need `HttpError`, for database operations `DbError`, for searching operations `NotFoundError` and so on. + +Our errors should inherit from with the basic `Error` class and have basic error properties like `message`, `name` and, preferably, `stack`. But they also may have other properties of their own, e.g. `HttpError` objects may have `statusCode` property, that is `404` for the "page not found" error. + +Technically, we can use standalone classes for errors, because Javascript allows to use `throw` with any argument. But if we inherit from `Error`, then we can use `obj instanceof Error` check to identify error objects. So it's better to inherit from it. + +As we build our application, our own errors naturally form a hierarchy, for instance `HttpTimeoutError` may inherit from `HttpError`. Examples will follow soon. + +## Extending Error + +As an example, let's create a function `readUser(json)` that should read JSON with user data. We are getting that data from a remote server or, maybe it may be altered by a visitor, or just for the sheer safety -- we should to be aware of possible errors in `json`. + +Here's an example of how a valid `json` may look: +```js +let json = `{ "name": "John", "age": 30 }`; +``` + +If the function receives malformed `json`, then it should throw `SyntaxError`. Fortunately, `JSON.parse` does exactly that. + +...But if the `json` is correct, that doesn't mean it has all the data. For instance, if may not have `name` or `age`. + +That's called "data validation" -- we need to ensure that the data has all the necessary fields. And if the validation fails, then throwing `SyntaxError` would be wrong, because the data is syntactically correct. So we should throw `ValidationError` -- the error object of our own with the proper message and, preferable, with additional information about the offending field. + +Let's make the `ValidationError` class. But to better understand what we're extending -- here's the approximate code for built-in [Error class](https://tc39.github.io/ecma262/#sec-error-message): + +```js +class Error { + constructor(message) { + this.message = message; + this.name = "Error"; // (different names for different built-in errors) + this.stack = ; // non-standard! most environments support it + } +} +``` + +Now let's inherit from it: + +```js run untrusted +class ValidationError extends Error { + constructor(message) { + super(message); // (1) + this.name = "ValidationError"; // (2) + } +} + +function test() { + throw new ValidationError("Wops!"); +} + +try { + test(); +} catch(err) { + alert(err.message); // Wops! + alert(err.name); // ValidationError + alert(err.stack); // a list of nested calls with line numbers for each +} +``` + +Notes: + +1. In the line `(1)` we call the parent constructor to set the message. Javascript requires us to call `super` in the child constructor anyway. +2. The `name` property for our own errors should be assigned manually, otherwise it would be set by the superclass (to `"Error"`). + + +Let's try to use it in `readUser(json)`: + +```js run +class ValidationError extends Error { + constructor(message) { + super(message); + this.name = "ValidationError"; + } +} + +// Usage +function readUser(json) { + let user = JSON.parse(json); + + if (!user.age) { + throw new ValidationError("No field: age"); + } + if (!user.name) { + throw new ValidationError("No field: name"); + } + + return user; +} + +// Working example with try..catch + +try { + let user = readUser('{ "age": 25 }'); +} catch (err) { + if (err instanceof ValidationError) { +*!* + alert("Invalid data: " + err.message); // Invalid data: No field: name +*/!* + } else if (err instanceof SyntaxError) { + alert("JSON Syntax Error: " + err.message); + } else { + throw err; // unknown error, rethrow it + } +} +``` + +Everything works -- both our `ValidationError` and the built-in `SyntaxError` from `JSON.parse` are correctly handled. + +Please note how the code check for the error type in `catch (err) { ... }`. We could use `if (err.name == "ValidationError")`, but `if (err instanceof ValidationError)` is much better, because in the future we are going to extend `ValidationError`, make new subtypes of it, namely `PropertyRequiredError`. And `instanceof` check will continue to work. So that's future proof. + +Also it's important that if we meet an unknown error, then we just rethrow it. The `catch` only knows how to handle validation and syntax errors, other kinds (due to a typo in the code or such) should fall through. + +## Further inheritance + +The `ValidationError` class is very generic. Let's make a more concrete class `PropertyRequiredError`, exactly for the absent properties. It will carry additional information about the property that's missing. + +```js run +class ValidationError extends Error { + constructor(message) { + super(message); + this.name = "ValidationError"; + } +} + +*!* +class PropertyRequiredError extends ValidationError { + constructor(property) { + super("No property: " + property); + this.name = "PropertyRequiredError"; + this.property = property; + } +} +*/!* + +// Usage +function readUser(json) { + let user = JSON.parse(json); + + if (!user.age) { + throw new PropertyRequiredError("age"); + } + if (!user.name) { + throw new PropertyRequiredError("name"); + } + + return user; +} + +// Working example with try..catch + +try { + let user = readUser('{ "age": 25 }'); +} catch (err) { + if (err instanceof ValidationError) { +*!* + alert("Invalid data: " + err.message); // Invalid data: No property: name + alert(err.name); // PropertyRequiredError + alert(err.property); // name +*/!* + } else if (err instanceof SyntaxError) { + alert("JSON Syntax Error: " + err.message); + } else { + throw err; // unknown error, rethrow it + } +} +``` + +The new class `PropertyRequiredError` is easier to use, because we just pass the property name to it: `new PropertyRequiredError(property)`. The human-readable `message` is generated by the constructor. + +Plese note that `this.name` in `PropertyRequiredError` once again assigned manually. We could evade that by using `this.constructor.name` for `this.name` in the superclass. + +The generic solution would be to make `MyError` class that takes care of it, and inherit from it. + +For instance: + +```js run +class MyError extends Error { + constructor(message) { + super(message); +*!* + this.name = this.constructor.name; +*/!* + } +} + +class ValidationError extends MyError { } + +class PropertyRequiredError extends ValidationError { + constructor(property) { + super("No property: " + property); + this.property = property; + } +} + +alert( new PropertyRequiredError("field").name ); // PropertyRequiredError +``` + + +## Wrapping exceptions + +The purpose of the function `readUser` in the code above is -- to "read the user data", right? There may occur different kinds of errors in the process, not only `SyntaxError` and `ValidationError`, but probably others if we continue developing it. + +Right now the code which calls `readUser` uses multiple `if` in `catch` to check for different error types and rethrow if the error is unknown. + +But the important questions is: do we want to check for all these types every time we call `readUser`? + +Often the answer is: "No". The outer code wants to be "one level above all that". It wants to have some kind of "data reading error", and why exactly it happened -- is usually irrelevant (the message has the info). Or, even better if there is a way to get more details, but only if it wants to. + +In our case, when a data-reading error occurs, we will create an object of the new class `ReadError`, that will provide the proper message. And we'll also keep the original error in its `cause` property, just in case. + +```js run +class ReadError extends Error { + constructor(message, cause) { + super(message); + this.cause = cause; + this.name = 'ReadError'; + } +} + +class ValidationError extends Error { /*...*/ } +class PropertyRequiredError extends ValidationError { /* ... */ } + +function validateUser(user) { + if (!user.age) { + throw new PropertyRequiredError("age"); + } + + if (!user.name) { + throw new PropertyRequiredError("name"); + } +} + +function readUser(json) { + let user; + + try { + user = JSON.parse(json); + } catch (err) { + if (err instanceof SyntaxError) { + throw new ReadError("Syntax Error", err); + } else { + throw err; + } + } + + try { + validateUser(user); + } catch (err) { + if (err instanceof ValidationError) { + throw new ReadError("Validation Error", err); + } else { + throw err; + } + } + +} + +try { + readUser('{bad json}'); +} catch (e) { + if (e instanceof ReadError) { +*!* + alert(e); + // Original error: SyntaxError: Unexpected token b in JSON at position 1 + alert("Original error: " + e.cause); +*/!* + } else { + throw e; + } +} +``` + +The approach is called "wrapping exceptions", because we take "low level exceptions" and "wrap" them into `ReadError` that is more abstract and more convenient to use for the calling code. + + +## Summary + +- We can inherit from `Error` and other built-in error classes normally, just need to take care of `name` property and don't forget to call `super`. +- Most of the time, we should use `instanceof` to check for particular errors. It also works with inheritance. But sometimes we have an error object coming from the 3rd-party library and there's no easy way to get the class. Then `name` property can be used for such checks. +- Wrapping exceptions is a widespread technique when a function handles low-level exceptions and makes a higher-level object to report about the errors. Low-level exceptions sometimes become properties of that object like `err.cause` in the examples above, but that's not strictly required. diff --git a/1-js/08-error-handling/index.md b/1-js/08-error-handling/index.md new file mode 100644 index 00000000..face61c6 --- /dev/null +++ b/1-js/08-error-handling/index.md @@ -0,0 +1 @@ +# Error handling diff --git a/1-js/7-advanced-syntax/12-oop-errors/1-format-error/solution.md b/1-js/7-advanced-syntax/12-oop-errors/1-format-error/solution.md deleted file mode 100644 index ba8c9f46..00000000 --- a/1-js/7-advanced-syntax/12-oop-errors/1-format-error/solution.md +++ /dev/null @@ -1,27 +0,0 @@ -```js run -function FormatError(message) { - this.name = "FormatError"; - - this.message = message; - - if (Error.captureStackTrace) { - Error.captureStackTrace(this, this.constructor); - } else { - this.stack = (new Error()).stack; - } - -} - -FormatError.prototype = Object.create(SyntaxError.prototype); -FormatError.prototype.constructor = FormatError; - -// Использование - -var err = new FormatError("ошибка форматирования"); - -alert( err.message ); // ошибка форматирования -alert( err.name ); // FormatError -alert( err.stack ); // стек на момент генерации ошибки - -alert( err instanceof SyntaxError ); // true -``` \ No newline at end of file diff --git a/1-js/7-advanced-syntax/12-oop-errors/1-format-error/task.md b/1-js/7-advanced-syntax/12-oop-errors/1-format-error/task.md deleted file mode 100644 index d405227f..00000000 --- a/1-js/7-advanced-syntax/12-oop-errors/1-format-error/task.md +++ /dev/null @@ -1,20 +0,0 @@ -importance: 5 - ---- - -# Унаследуйте от SyntaxError - -Создайте ошибку `FormatError`, которая будет наследовать от встроенного класса `SyntaxError`. - -Синтаксис для её создания -- такой же, как обычно: - -```js -var err = new FormatError("ошибка форматирования"); - -alert( err.message ); // ошибка форматирования -alert( err.name ); // FormatError -alert( err.stack ); // стек на момент генерации ошибки - -alert( err instanceof SyntaxError ); // true -``` - diff --git a/1-js/7-advanced-syntax/12-oop-errors/article.md b/1-js/7-advanced-syntax/12-oop-errors/article.md deleted file mode 100644 index 83fe1b10..00000000 --- a/1-js/7-advanced-syntax/12-oop-errors/article.md +++ /dev/null @@ -1,280 +0,0 @@ -# Свои ошибки, наследование от Error - -Когда мы работаем с внешними данными, возможны самые разные ошибки. - -Если приложение сложное, то ошибки естественным образом укладываются в иерархию, разобраться в которой помогает `instanceof`. - -## Свой объект ошибки - -Для примера создадим функцию `readUser(json)`, которая будет разбирать JSON с данными посетителя. Мы его получаем с сервера -- может, нашего, а может -- чужого, в общем -- желательно проверить на ошибки. А может, это даже и не JSON, а какие-то другие данные -- не важно, для наглядности поработаем с JSON. - -Пример `json` на входе в функцию: `{ "name": "Вася", "age": 30 }`. - -В процессе работы `readUser` возможны различные ошибки. Одна -- очевидно, `SyntaxError` -- если передан некорректный JSON. - -Но могут быть и другие, например `PropertyError` -- эта ошибка будет возникать, если в прочитанном объекте нет свойства `name` или `age`. - -Реализуем класс `PropertyError`: - -```js -function PropertyError(property) { - Error.call(this, property) ; - this.name = "PropertyError"; - - this.property = property; - this.message = "Ошибка в свойстве " + property; - - if (Error.captureStackTrace) { - Error.captureStackTrace(this, PropertyError); - } else { - this.stack = (new Error()).stack; - } - -} - -PropertyError.prototype = Object.create(Error.prototype); -``` - -В этом коде вы можете видеть ряд важных деталей, важных именно для ошибок: - -`name` -- имя ошибки. -: Должно совпадать с именем функции. - -`message` -- сообщение об ошибке. -: Несмотря на то, что `PropertyError` наследует от `Error` (последняя строка), конструктор у неё немного другой. Он принимает не сообщение об ошибке, а название свойства `property`, ну а сообщение генерируется из него. - - В результате в объекте ошибки есть как стандартное свойство `message`, так и более точное `property`. - - Это частая практика -- добавлять в объект ошибки свойства, которых нет в базовых объектах `Error`, более подробно описывающие ситуацию для данного класса ошибок. - -`stack` -- стек вызовов, которые в итоге привели к ошибке. -: У встроенных объектов `Error` это свойство есть автоматически, вот к примеру: - ```js run - function f() { - alert( new Error().stack ); - } - - f(); // выведет список вложенных вызовов, с номерами строк, где они были сделаны - ``` - - Если же объект ошибки делаем мы, то "по умолчанию" такого свойства у него не будет. Нам нужно как-то самим узнавать последовательность вложенных вызовов на текущий момент. Однако удобного способа сделать это в JavaScript нет, поэтому мы поступаем хитро и копируем его из нового объекта `new Error`, который генерируем тут же. - - В V8 (Chrome, Opera, Node.JS) есть нестандартное расширение [Error.captureStackTrace](https://code.google.com/p/v8-wiki/wiki/JavaScriptStackTraceApi), которое позволяет получить стек. - - Это делает строка из кода выше: - ```js - Error.captureStackTrace(this, PropertyError); - ``` - - Такой вызов записывает в объект `this` (текущий объект ошибки) стек вызовов, ну а второй аргумент -- вообще не обязателен, но если есть, то говорит, что при генерации стека нужно на этой функции остановиться. В результате в стеке будет информация о цепочке вложенных вызовов вплоть до вызова `PropertyError`. - - То есть, будет последовательность вызовов до генерации ошибки, но не включая код самого конструктора ошибки, который, как правило, не интересен. Такое поведение максимально соответствует встроенным ошибкам JavaScript. - -```smart header="Конструктор родителя здесь не обязателен" -Обычно, когда мы наследуем, то вызываем конструктор родителя. В данном случае вызов выглядит как `Error.call(this, message)`. - -Строго говоря, этот вызов здесь не обязателен. Встроенный конструктор `Error` ничего полезного не делает, даже свойство `this.message` (не говоря уже об `name` и `stack`) не назначает. Единственный возможный смысл его вызова -- он ставит специальное внутреннее свойство `[[ErrorData]]`, которое выводится в `toString` и позволяет увидеть, что это ошибка. Поэтому по стандарту вызывать конструктор `Error` при наследовании в таких случаях рекомендовано. -``` - -## instanceof + try..catch = ♡ - -Давайте теперь используем наш новый класс для `readUser`: - -```js run -*!* -// Объявление -*/!* -function PropertyError(property) { - this.name = "PropertyError"; - - this.property = property; - this.message = "Ошибка в свойстве " + property; - - if (Error.captureStackTrace) { - Error.captureStackTrace(this, PropertyError); - } else { - this.stack = (new Error()).stack; - } - -} - -PropertyError.prototype = Object.create(Error.prototype); - -*!* -// Генерация ошибки -*/!* -function readUser(data) { - - var user = JSON.parse(data); - - if (!user.age) { - throw new PropertyError("age"); - } - - if (!user.name) { - throw new PropertyError("name"); - } - - return user; -} - -*!* -// Запуск и try..catch -*/!* - -try { - var user = readUser('{ "age": 25 }'); -} catch (err) { - if (err instanceof PropertyError) { - if (err.property == 'name') { - // если в данном месте кода возможны анонимы, то всё нормально -*!* - alert( "Здравствуйте, Аноним!" ); -*/!* - } else { - alert( err.message ); // Ошибка в свойстве ... - } - } else if (err instanceof SyntaxError) { - alert( "Ошибка в синтаксисе данных: " + err.message ); - } else { - throw err; // неизвестная ошибка, не знаю что с ней делать - } -} -``` - -Всё работает -- и наша ошибка `PropertyError` и встроенная `SyntaxError` корректно генерируются, перехватываются, обрабатываются. - -Обратим внимание на проверку типа ошибки в `try..catch`. Оператор `instanceof` проверяет класс с учётом наследования. Это значит, что если мы в дальнейшем решим создать новый тип ошибки, наследующий от `PropertyError`, то проверка `err instanceof PropertyError` для класса-наследника тоже будет работать. Код получился расширяемым, это очень важно. - -## Дальнейшее наследование - -`PropertyError` -- это просто общего вида ошибка в свойстве. Создадим ошибку `PropertyRequiredError`, которая означает, что свойства нет. - -Это подвид `PropertyError`, так что унаследуем от неё. Общий вид конструктора-наследника -- стандартный: - -```js -function PropertyRequiredError(property) { - // вызываем конструктор родителя и передаём текущие аргументы - PropertyError.apply(this, arguments); - ... -} -``` - -Достаточно ли в наследнике просто вызвать конструктор родителя? Увы, нет. - -Если так поступить, то свойство `this.name` будет некорректным, да и `Error.captureStackTrace` тоже получит неправильную функцию вторым параметром. - -Можно ли как-то поправить конструктор родителя, чтобы от него было проще наследовать? - -Для этого нужно убрать из него упоминания о конкретном классе `PropertyError`, чтобы сделать код универсальным. Частично -- это возможно. Как мы помним, существует свойство `constructor`, которое есть в `prototype` по умолчанию, и которое мы можем намеренно сохранить при наследовании. - -Исправим родителя `PropertyError` для более удобного наследования от него: - -```js -function PropertyError(property) { - this.name = "PropertyError"; - - this.property = property; - this.message = "Ошибка в свойстве " + property; - - if (Error.captureStackTrace) { - Error.captureStackTrace(this, *!*this.constructor*/!*); // (*) - } else { - this.stack = (new Error()).stack; - } - -} - -PropertyError.prototype = Object.create(Error.prototype); -*!* -PropertyError.prototype.constructor = PropertyError; -*/!* -``` - -В строке `(*)` вместо ссылки на `PropertyError` используем `constructor` чтобы получить именно конструктор для текущего объекта. В наследнике там будет `PropertyRequiredError`, как и задумано. - -Мы убрали одну жёсткую привязку к `PropertyError`, но со второй (`this.name`), увы, сложности. Оно должно содержать имя ошибки, то есть, имя её функции-конструктора. Его можно получить через `this.name = this.constructor.name`, но в IE11- это работать не будет. - -Если подерживать IE11-, то тут уж придётся в наследнике его записывать вручную. - -Полный код для наследника: - -```js -function PropertyRequiredError(property) { - PropertyError.apply(this, arguments); - this.name = 'PropertyRequiredError'; - this.message = 'Отсутствует свойство ' + property; -} - -PropertyRequiredError.prototype = Object.create(PropertyError.prototype); -PropertyRequiredError.prototype.constructor = PropertyRequiredError; - -var err = new PropertyRequiredError("age"); -// пройдёт проверку -alert( err instanceof PropertyError ); // true -``` - -Здесь заодно и `message` в наследнике было перезаписано на более точное. Если хочется избежать записи и перезаписи, то можно оформить его в виде геттера через `Object.defineProperty`. - -## Итого - -- Чтобы наследовать от ошибок `Error`, нужно самостоятельно позаботиться о `name`, `message` и `stack`. -- Благодаря тому, что `instanceof` поддерживает наследование, удобно организуются проверки на нужный тип. В иерархию ошибок можно в любой момент добавить новые классы, с понятным кодом и предсказуемым поведением. - -Чтобы создавать наследники от `Error` было проще, можно создать класс `CustomError`, записать в него универсальный код, наподобие `PropertyError` и далее наследовать уже от него: - -```js -*!* -// общего вида "наша" ошибка -*/!* -function CustomError(message) { - this.name = "CustomError"; - this.message = message; - - if (Error.captureStackTrace) { - Error.captureStackTrace(this, this.constructor); - } else { - this.stack = (new Error()).stack; - } - -} - -CustomError.prototype = Object.create(Error.prototype); -CustomError.prototype.constructor = CustomError; - -*!* -// наследник -*/!* -function PropertyError(property) { - CustomError.call(this, "Отсутствует свойство " + property) - this.name = "PropertyError"; - - this.property = property; -} - -PropertyError.prototype = Object.create(CustomError.prototype); -PropertyError.prototype.constructor = PropertyError; - -*!* -// и ещё уровень -*/!* -function PropertyRequiredError(property) { - PropertyError.call(this, property); - this.name = 'PropertyRequiredError'; - this.message = 'Отсутствует свойство ' + property; -} - -PropertyRequiredError.prototype = Object.create(PropertyError.prototype); -PropertyRequiredError.prototype.constructor = PropertyRequiredError; - -*!* -// использование -*/!* -var err = new PropertyRequiredError("age"); -// пройдёт проверку -alert( err instanceof PropertyRequiredError ); // true -alert( err instanceof PropertyError ); // true -alert( err instanceof CustomError ); // true -alert( err instanceof Error ); // true -``` - diff --git a/1-js/7-advanced-syntax/4-try-catch/1-finally-or-code-after/solution.md b/1-js/7-advanced-syntax/4-try-catch/1-finally-or-code-after/solution.md deleted file mode 100644 index 4fc300ab..00000000 --- a/1-js/7-advanced-syntax/4-try-catch/1-finally-or-code-after/solution.md +++ /dev/null @@ -1,43 +0,0 @@ -Разница в поведении станет очевидной, если рассмотреть код внутри функции. - -Поведение будет различным, если управление каким-то образом выпрыгнет из `try..catch`. - -Например, `finally` сработает после `return`, но до передачи управления внешнему коду: - -```js -function f() { - try { - ... -*!* - return result; -*/!* - } catch (e) { - ... - } finally { - очистить ресурсы - } -} -``` - -Или же управление может выпрыгнуть из-за `throw`: - -```js -function f() { - try { - ... - - } catch (e) { - ... - if(не умею обрабатывать эту ошибку) { -*!* - throw e; -*/!* - } - - } finally { - очистить ресурсы - } -} -``` - -В этих случаях именно `finally` гарантирует выполнение кода до окончания работы `f`, просто код не будет вызван. diff --git a/1-js/7-advanced-syntax/4-try-catch/1-finally-or-code-after/task.md b/1-js/7-advanced-syntax/4-try-catch/1-finally-or-code-after/task.md deleted file mode 100644 index e0234d06..00000000 --- a/1-js/7-advanced-syntax/4-try-catch/1-finally-or-code-after/task.md +++ /dev/null @@ -1,39 +0,0 @@ -importance: 5 - ---- - -# Finally или просто код? - -Сравните два фрагмента кода. - -1. Первый использует `finally` для выполнения кода по выходу из `try..catch`: - - ```js - try { - начать работу - работать - } catch (e) { - обработать ошибку - } finally { - *!* - финализация: завершить работу - */!* - } - ``` -2. Второй фрагмент просто ставит очистку ресурсов за `try..catch`: - - ```js - try { - начать работу - } catch (e) { - обработать ошибку - } - - *!* - финализация: завершить работу - */!* - ``` - -Нужно, чтобы код финализации всегда выполнялся при выходе из блока `try..catch` и, таким образом, заканчивал начатую работу. Имеет ли здесь `finally` какое-то преимущество или оба фрагмента работают одинаково? - -Если имеет, то дайте пример когда код с `finally` работает верно, а без -- неверно. diff --git a/1-js/7-advanced-syntax/index.md b/1-js/7-advanced-syntax/index.md deleted file mode 100644 index fcebcff5..00000000 --- a/1-js/7-advanced-syntax/index.md +++ /dev/null @@ -1 +0,0 @@ -# More syntax [todo move error handling] diff --git a/1-js/9-object-inheritance/05-native-prototypes/1-defer-to-prototype/solution.md b/1-js/9-object-inheritance/05-native-prototypes/1-defer-to-prototype/solution.md deleted file mode 100644 index 7d457ce4..00000000 --- a/1-js/9-object-inheritance/05-native-prototypes/1-defer-to-prototype/solution.md +++ /dev/null @@ -1,14 +0,0 @@ - - -```js run -Function.prototype.defer = function(ms) { - setTimeout(this, ms); -} - -function f() { - alert( "привет" ); -} - -f.defer(1000); // выведет "привет" через 1 секунду -``` - diff --git a/1-js/9-object-inheritance/05-native-prototypes/1-defer-to-prototype/task.md b/1-js/9-object-inheritance/05-native-prototypes/1-defer-to-prototype/task.md deleted file mode 100644 index 8d16ebf7..00000000 --- a/1-js/9-object-inheritance/05-native-prototypes/1-defer-to-prototype/task.md +++ /dev/null @@ -1,18 +0,0 @@ -importance: 5 - ---- - -# Добавить функциям defer - -Добавьте всем функциям в прототип метод `defer(ms)`, который откладывает вызов функции на `ms` миллисекунд. - -После этого должен работать такой код: - -```js -function f() { - alert( "привет" ); -} - -f.defer(1000); // выведет "привет" через 1 секунду -``` - diff --git a/1-js/9-object-inheritance/05-native-prototypes/2-defer-to-prototype-extended/solution.md b/1-js/9-object-inheritance/05-native-prototypes/2-defer-to-prototype-extended/solution.md deleted file mode 100644 index 5dae0e65..00000000 --- a/1-js/9-object-inheritance/05-native-prototypes/2-defer-to-prototype-extended/solution.md +++ /dev/null @@ -1,20 +0,0 @@ - - -```js run -Function.prototype.defer = function(ms) { - var f = this; - return function(...args) { - let context = this; - setTimeout(function() { - f.apply(context, args); - }, ms); - } -} - -// проверка -function f(a, b) { - alert( a + b ); -} - -f.defer(1000)(1, 2); // выведет 3 через 1 секунду. -``` diff --git a/1-js/9-object-inheritance/05-native-prototypes/2-defer-to-prototype-extended/task.md b/1-js/9-object-inheritance/05-native-prototypes/2-defer-to-prototype-extended/task.md deleted file mode 100644 index 2a8c2051..00000000 --- a/1-js/9-object-inheritance/05-native-prototypes/2-defer-to-prototype-extended/task.md +++ /dev/null @@ -1,20 +0,0 @@ -importance: 4 - ---- - -# Добавить функциям defer с аргументами - -Добавьте всем функциям в прототип метод defer(ms), который возвращает обёртку, откладывающую вызов функции на ms миллисекунд. - -Например, должно работать так: - -```js -function f(a, b) { - alert( a + b ); -} - -f.defer(1000)(1, 2); // выведет 3 через 1 секунду. -``` - -То есть, должны корректно передаваться аргументы. - diff --git a/1-js/9-object-inheritance/10-class-inheritance/class-inheritance-array-object.png b/1-js/9-object-inheritance/10-class-inheritance/class-inheritance-array-object.png deleted file mode 100644 index 695b577a..00000000 Binary files a/1-js/9-object-inheritance/10-class-inheritance/class-inheritance-array-object.png and /dev/null differ diff --git a/1-js/9-object-inheritance/10-class-inheritance/class-inheritance-array-object@2x.png b/1-js/9-object-inheritance/10-class-inheritance/class-inheritance-array-object@2x.png deleted file mode 100644 index e6ebbb1d..00000000 Binary files a/1-js/9-object-inheritance/10-class-inheritance/class-inheritance-array-object@2x.png and /dev/null differ diff --git a/1-js/plan3.txt b/1-js/plan3.txt index 66363cab..ae5e9c63 100644 --- a/1-js/plan3.txt +++ b/1-js/plan3.txt @@ -72,31 +72,6 @@ deeper ------- -<< intl -<<< descriptors (TODO: LATER, need JSON to output, better after inheritance to explain getOwnProps) -<<< getter setter - - -constructors -classes -instanceof - -после 4-object сделать - descriptors - - +intl? proxy? - -error-handling - try..catch - object-oriented error handling (inheritance, rethrow etc) - -more-features - try..catch - try..catch in decorators! - setTimeout - JSON - - -====== -class A extends Object != class A +eval? diff --git a/archive/1-delay/solution.md b/archive/1-delay/solution.md deleted file mode 100644 index 722a2c26..00000000 --- a/archive/1-delay/solution.md +++ /dev/null @@ -1,26 +0,0 @@ - - -```js run -function delay(f, ms) { - -*!* - return function() { - setTimeout(() => f.apply(this, arguments), ms); - }; -*/!* - -} - -function f(x) { - alert(x); -} - -let f1000 = delay(f, 1000); -let f1500 = delay(f, 1500); - -f1000("test"); // shows "test" after 1000ms -f1500("test"); // shows "test" after 1500ms -``` - -Arrow function makes it easy, because `setTimeout` uses arguments and context of the wrapper . - diff --git a/1-js/7-advanced-syntax/4-try-catch/2-eval-calculator-errors/solution.md b/archive/2-eval-calculator-errors/solution.md similarity index 100% rename from 1-js/7-advanced-syntax/4-try-catch/2-eval-calculator-errors/solution.md rename to archive/2-eval-calculator-errors/solution.md diff --git a/1-js/7-advanced-syntax/4-try-catch/2-eval-calculator-errors/task.md b/archive/2-eval-calculator-errors/task.md similarity index 100% rename from 1-js/7-advanced-syntax/4-try-catch/2-eval-calculator-errors/task.md rename to archive/2-eval-calculator-errors/task.md diff --git a/archive/timing-decorator.md b/archive/timing-decorator.md new file mode 100644 index 00000000..6aae000e --- /dev/null +++ b/archive/timing-decorator.md @@ -0,0 +1,105 @@ + + +## Instrumentation: timing decorator + +Let's say we have a function and want to measure time it takes to run. + +Of course, we could modify it. Add something like `timerStart()` to the start and `timerEnd()` to all exit points. Then later we may want to log which arguments it receives and results. That requires additional code as well. + +That is called [instrumentation](https://en.wikipedia.org/wiki/Instrumentation) of the code -- adding stuff to measure times, log what's happening and do other watching/measuring without interfering with the main functionality. + +Putting instrumentation inside the function manually is not pretty at all. It takes space, shadows the core functionality and makes it harder to debug. + +There are tools that analyze javascript code and add instrumentation calls to it automatically. But here we'll take a "median" approach. We will "wrap" instrumentation over function without touching its code. + +What we going to do is a special function `timingDecorator(func)`, that takes a function `func` and returns a "wrapper" around it, that transfers all calls to `func` and measures time they take. + +For simplicity let's assume that `func` has only one argument. + +The code with `timingDecorator` and example function: + + + + +```js run +function fibo(n) { // a function to measure, here we count fibonacci number + return (n > 2) ? fibo(n - 1) + fibo(n - 2) : 1; +} + +let timers = {}; // timers to store data + +function timingDecorator(func) { + return function(x) { + let start = performance.now(); + + let result = func(x); + + let time = performance.now() - start; + + if (!timers[func.name]) timers[func.name] = 0; + timers[func.name] += time; + + return result; + }; +} + +// decorate it +fibo = timingDecorator(fibo); + +// run +alert( fibo(10) ); // 55 +alert( fibo(20) ); // 6765 +alert( fibo(30) ); // 832040 + +alert( `Total time: ${timers.fibo.toFixed(3)}ms` ); // total count of fibo calls +``` + +При помощи декоратора `timingDecorator` мы сможем взять произвольную функцию и одним движением руки прикрутить к ней измеритель времени. + +Его реализация: + +```js run +var timers = {}; + +// прибавит время выполнения f к таймеру timers[timer] +function timingDecorator(f, timer) { + return function() { + var start = performance.now(); + + var result = f.apply(this, arguments); // (*) + + if (!timers[timer]) timers[timer] = 0; + timers[timer] += performance.now() - start; + + return result; + } +} + +// функция может быть произвольной, например такой: +var fibonacci = function f(n) { + return (n > 2) ? f(n - 1) + f(n - 2) : 1; +} + +*!* +// использование: завернём fibonacci в декоратор +fibonacci = timingDecorator(fibonacci, "fibo"); +*/!* + +// неоднократные вызовы... +alert( fibonacci(10) ); // 55 +alert( fibonacci(20) ); // 6765 +// ... + +*!* +// в любой момент можно получить общее количество времени на вызовы +alert( timers.fibo + 'мс' ); +*/!* +``` + +Обратим внимание на строку `(*)` внутри декоратора, которая и осуществляет передачу вызова: + +```js +var result = f.apply(this, arguments); // (*) +``` + +Этот приём называется "форвардинг вызова" (от англ. forwarding): текущий контекст и аргументы через `apply` передаются в функцию `f`, так что изнутри `f` всё выглядит так, как была вызвана она напрямую, а не декоратор. diff --git a/figures.sketch b/figures.sketch index a5677be0..5819b5c3 100644 Binary files a/figures.sketch and b/figures.sketch differ