Merge pull request #2283 from leviding/patch-31

FIX: some typo error
This commit is contained in:
Ilya Kantor 2020-11-25 08:48:09 +03:00 committed by GitHub
commit 9700f82b12
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 21 additions and 21 deletions

View file

@ -9,7 +9,7 @@ The optional chaining `?.` is a safe way to access nested object properties, eve
If you've just started to read the tutorial and learn JavaScript, maybe the problem hasn't touched you yet, but it's quite common.
As an example, let's say we have `user` objects that hold the information about our users.
As an example, let's say we have `user` objects that hold the information about our users.
Most of our users have addresses in `user.address` property, with the street `user.address.street`, but some did not provide them.
@ -21,7 +21,7 @@ let user = {}; // a user without "address" property
alert(user.address.street); // Error!
```
That's the expected result. JavaScript works like this. As `user.address` is `undefined`, an attempt to get `user.address.street` fails with an error.
That's the expected result. JavaScript works like this. As `user.address` is `undefined`, an attempt to get `user.address.street` fails with an error.
In many practical cases we'd prefer to get `undefined` instead of an error here (meaning "no street").
@ -56,7 +56,7 @@ let user = {}; // user has no address
alert(user.address ? user.address.street ? user.address.street.name : null : null);
```
That's just awful, one may even have problems understanding such code.
That's just awful, one may even have problems understanding such code.
Don't even care to, as there's a better way to write it, using the `&&` operator:

View file

@ -30,7 +30,7 @@ let array = [ john ];
john = null; // overwrite the reference
*!*
// the object previously referenced by john is stored inside the array
// the object previously referenced by john is stored inside the array
// therefore it won't be garbage-collected
// we can get it as array[0]
*/!*

View file

@ -21,9 +21,9 @@ Here's the code for it (uses the debounce decorator from the [Lodash library](ht
```js
let f = _.debounce(alert, 1000);
f("a");
f("a");
setTimeout( () => f("b"), 200);
setTimeout( () => f("c"), 500);
setTimeout( () => f("c"), 500);
// debounced function waits 1000ms after the last call and then runs: alert("c")
```

View file

@ -12,7 +12,7 @@ In JavaScript, objects have a special hidden property `[[Prototype]]` (as named
![prototype](object-prototype-empty.svg)
When we read a property from `object`, and it's missing, JavaScript automatically takes it from the prototype. In programming, such thing is called "prototypal inheritance". And soon we'll study many examples of such inheritance, as well as cooler language features built upon it.
When we read a property from `object`, and it's missing, JavaScript automatically takes it from the prototype. In programming, such thing is called "prototypal inheritance". And soon we'll study many examples of such inheritance, as well as cooler language features built upon it.
The property `[[Prototype]]` is internal and hidden, but there are many ways to set it.
@ -133,11 +133,11 @@ Also it may be obvious, but still: there can be only one `[[Prototype]]`. An obj
```smart header="`__proto__` is a historical getter/setter for `[[Prototype]]`"
It's a common mistake of novice developers not to know the difference between these two.
It's a common mistake of novice developers not to know the difference between these two.
Please note that `__proto__` is *not the same* as the internal `[[Prototype]]` property. It's a getter/setter for `[[Prototype]]`. Later we'll see situations where it matters, for now let's just keep it in mind, as we build our understanding of JavaScript language.
Please note that `__proto__` is *not the same* as the internal `[[Prototype]]` property. It's a getter/setter for `[[Prototype]]`. Later we'll see situations where it matters, for now let's just keep it in mind, as we build our understanding of JavaScript language.
The `__proto__` property is a bit outdated. It exists for historical reasons, modern JavaScript suggests that we should use `Object.getPrototypeOf/Object.setPrototypeOf` functions instead that get/set the prototype. We'll also cover these functions later.
The `__proto__` property is a bit outdated. It exists for historical reasons, modern JavaScript suggests that we should use `Object.getPrototypeOf/Object.setPrototypeOf` functions instead that get/set the prototype. We'll also cover these functions later.
By the specification, `__proto__` must only be supported by browsers. In fact though, all environments including server-side support `__proto__`, so we're quite safe using it.

View file

@ -50,7 +50,7 @@ As we can see, the new function is a wrapper around the original `loadScript` fu
Now `loadScriptPromise` fits well in promise-based code. If we like promises more than callbacks (and soon we'll see more reasons for that), then we will use it instead.
In practice we may need to promisify more than one function, so it makes sense to use a helper.
In practice we may need to promisify more than one function, so it makes sense to use a helper.
We'll call it `promisify(f)`: it accepts a to-promisify function `f` and returns a wrapper function.

View file

@ -363,7 +363,7 @@ More explanations about how it works:
- The initial URL is `https://api.github.com/repos/<repo>/commits`, and the next page will be in the `Link` header of the response.
- The `fetch` method allows us to supply authorization and other headers if needed -- here GitHub requires `User-Agent`.
2. The commits are returned in JSON format.
3. We should get the next page URL from the `Link` header of the response. It has a special format, so we use a regular expression for that (we will lern this feature in [Regular expressions](info:regular-expressions)).
3. We should get the next page URL from the `Link` header of the response. It has a special format, so we use a regular expression for that (we will learn this feature in [Regular expressions](info:regular-expressions)).
- The next page URL may look like `https://api.github.com/repositories/93253246/commits?page=2`. It's generated by GitHub itself.
4. Then we yield the received commits one by one, and when they finish, the next `while(url)` iteration will trigger, making one more request.