commit
9700f82b12
11 changed files with 21 additions and 21 deletions
|
@ -12,7 +12,7 @@ In JavaScript, objects have a special hidden property `[[Prototype]]` (as named
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
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.
|
The property `[[Prototype]]` is internal and hidden, but there are many ways to set it.
|
||||||
|
|
||||||
|
@ -135,7 +135,7 @@ 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]]`"
|
```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.
|
||||||
|
|
||||||
|
|
|
@ -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 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`.
|
- 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.
|
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.
|
- 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.
|
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.
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ When `abort()` is called:
|
||||||
|
|
||||||
Generally, we have two parties in the process:
|
Generally, we have two parties in the process:
|
||||||
1. The one that performs an cancelable operation, it sets a listener on `controller.signal`.
|
1. The one that performs an cancelable operation, it sets a listener on `controller.signal`.
|
||||||
2. The one one that cancels: it calls `controller.abort()` when needed.
|
2. The one that cancels: it calls `controller.abort()` when needed.
|
||||||
|
|
||||||
Here's the full example (without `fetch` yet):
|
Here's the full example (without `fetch` yet):
|
||||||
|
|
||||||
|
|
|
@ -217,8 +217,8 @@ Normally, when a document is unloaded, all associated network requests are abort
|
||||||
|
|
||||||
It has a few limitations:
|
It has a few limitations:
|
||||||
|
|
||||||
- We can't send megabytes: the body limit for `keepalive` requests is 64kb.
|
- We can't send megabytes: the body limit for `keepalive` requests is 64KB.
|
||||||
- If we need to gather a lot of statistics about the visit, we should send it out regularly in packets, so that there won't be a lot left for the last `onunload` request.
|
- If we need to gather a lot of statistics about the visit, we should send it out regularly in packets, so that there won't be a lot left for the last `onunload` request.
|
||||||
- This limit applies to all `keepalive` requests together. In other words, we can perform multiple `keepalive` requests in parallel, but the sum of their body lengths should not exceed 64kb.
|
- This limit applies to all `keepalive` requests together. In other words, we can perform multiple `keepalive` requests in parallel, but the sum of their body lengths should not exceed 64KB.
|
||||||
- We can't handle the server response if the document is unloaded. So in our example `fetch` will succeed due to `keepalive`, but subsequent functions won't work.
|
- We can't handle the server response if the document is unloaded. So in our example `fetch` will succeed due to `keepalive`, but subsequent functions won't work.
|
||||||
- In most cases, such as sending out statistics, it's not a problem, as server just accepts the data and usually sends an empty response to such requests.
|
- In most cases, such as sending out statistics, it's not a problem, as server just accepts the data and usually sends an empty response to such requests.
|
||||||
|
|
|
@ -70,7 +70,7 @@ As you can see, `subscribe` function makes a fetch, then waits for the response,
|
||||||
```warn header="Server should be ok with many pending connections"
|
```warn header="Server should be ok with many pending connections"
|
||||||
The server architecture must be able to work with many pending connections.
|
The server architecture must be able to work with many pending connections.
|
||||||
|
|
||||||
Certain server architectures run one process per connection; resulting in there being as many processes as there are connections, while each process consumes quite a bit of memory. So, too many connections will just consume it all.
|
Certain server architectures run one process per connection, resulting in there being as many processes as there are connections, while each process consumes quite a bit of memory. So, too many connections will just consume it all.
|
||||||
|
|
||||||
That's often the case for backends written in languages like PHP and Ruby.
|
That's often the case for backends written in languages like PHP and Ruby.
|
||||||
|
|
||||||
|
|
|
@ -3,5 +3,5 @@
|
||||||
What's the match here?
|
What's the match here?
|
||||||
|
|
||||||
```js
|
```js
|
||||||
"123 456".match(/\d+? \d+?/g) ); // ?
|
alert( "123 456".match(/\d+? \d+?/g) ); // ?
|
||||||
```
|
```
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue