From 80956ed877518b0f270535b08d49608fc29cdde5 Mon Sep 17 00:00:00 2001 From: Ilya Kantor Date: Sun, 16 May 2021 12:01:01 +0300 Subject: [PATCH] closes #2600 --- 1-js/02-first-steps/02-structure/article.md | 4 ++-- .../4-new-object-same-constructor/solution.md | 11 ++++++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/1-js/02-first-steps/02-structure/article.md b/1-js/02-first-steps/02-structure/article.md index cf1dd53d..7c6086d0 100644 --- a/1-js/02-first-steps/02-structure/article.md +++ b/1-js/02-first-steps/02-structure/article.md @@ -61,7 +61,7 @@ If you're curious to see a concrete example of such an error, check this code ou No need to think about the meaning of the brackets `[]` and `forEach` yet. We'll study them later. For now, just remember the result of the code: it shows `1` then `2`. -Now, let's add an `alert` before the code and *not* finish it with a semicolon: +Let's add an `alert` before the code and *not* finish it with a semicolon: ```js run no-beautify alert("There will be an error") @@ -69,7 +69,7 @@ alert("There will be an error") [1, 2].forEach(alert) ``` -Now if we run the code, only the first `alert` is shown and then we have an error! +Now if we run the code, only the first `alert` shows, and then we have an error! But everything is fine again if we add a semicolon after `alert`: ```js run diff --git a/1-js/08-prototypes/02-function-prototype/4-new-object-same-constructor/solution.md b/1-js/08-prototypes/02-function-prototype/4-new-object-same-constructor/solution.md index 0073e252..372d50dd 100644 --- a/1-js/08-prototypes/02-function-prototype/4-new-object-same-constructor/solution.md +++ b/1-js/08-prototypes/02-function-prototype/4-new-object-same-constructor/solution.md @@ -38,7 +38,12 @@ Why `user2.name` is `undefined`? Here's how `new user.constructor('Pete')` works: 1. First, it looks for `constructor` in `user`. Nothing. -2. Then it follows the prototype chain. The prototype of `user` is `User.prototype`, and it also has nothing. -3. The value of `User.prototype` is a plain object `{}`, its prototype is `Object.prototype`. And there is `Object.prototype.constructor == Object`. So it is used. +2. Then it follows the prototype chain. The prototype of `user` is `User.prototype`, and it also has no `constructor` (because we "forgot" to set it right!). +3. Going further up the chain, `User.prototype` is a plain object, its prototype is the built-in `Object.prototype`. +4. Finally, for the built-in `Object.prototype`, there's a built-in `Object.prototype.constructor == Object`. So it is used. -At the end, we have `let user2 = new Object('Pete')`. The built-in `Object` constructor ignores arguments, it always creates an empty object, similar to `let user2 = {}`, that's what we have in `user2` after all. +Finally, at the end, we have `let user2 = new Object('Pete')`. + +Probably, that's not what we want. We'd like to create `new User`, not `new Object`. That's the outcome of the missing `constructor`. + +(Just in case you're curious, the `new Object(...)` call converts its argument to an object. That's a theoretical thing, in practice no one calls `new Object` with a value, and generally we don't use `new Object` to make objects at all). \ No newline at end of file