Correct mis-use of "it's"
This commit is contained in:
parent
ac7daa516f
commit
6af9a2e2a4
14 changed files with 29 additions and 29 deletions
|
@ -76,7 +76,7 @@ In the code above, the second element of the array is skipped, the third one is
|
||||||
let [a, b, c] = "abc"; // ["a", "b", "c"]
|
let [a, b, c] = "abc"; // ["a", "b", "c"]
|
||||||
let [one, two, three] = new Set([1, 2, 3]);
|
let [one, two, three] = new Set([1, 2, 3]);
|
||||||
```
|
```
|
||||||
That works, because internally a destructuring assignment works by iterating over the right value. It's kind of syntax sugar for calling `for..of` over the value to the right of `=` and assigning the values.
|
That works, because internally a destructuring assignment works by iterating over the right value. It's a kind of syntax sugar for calling `for..of` over the value to the right of `=` and assigning the values.
|
||||||
````
|
````
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ There are two kinds of object properties.
|
||||||
|
|
||||||
The first kind is *data properties*. We already know how to work with them. All properties that we've been using until now were data properties.
|
The first kind is *data properties*. We already know how to work with them. All properties that we've been using until now were data properties.
|
||||||
|
|
||||||
The second type of properties is something new. It's *accessor properties*. They are essentially functions that execute on getting and setting a value, but look like regular properties to an external code.
|
The second type of property is something new. It's an *accessor property*. They are essentially functions that execute on getting and setting a value, but look like regular properties to an external code.
|
||||||
|
|
||||||
## Getters and setters
|
## Getters and setters
|
||||||
|
|
||||||
|
|
|
@ -55,7 +55,7 @@ Also, there's a global variable named by `id` that references the element:
|
||||||
```
|
```
|
||||||
|
|
||||||
```warn header="Please don't use id-named global variables to access elements"
|
```warn header="Please don't use id-named global variables to access elements"
|
||||||
This behavior is described [in the specification](http://www.whatwg.org/specs/web-apps/current-work/#dom-window-nameditem), so it's kind of standard. But it is supported mainly for compatibility.
|
This behavior is described [in the specification](http://www.whatwg.org/specs/web-apps/current-work/#dom-window-nameditem), so it's a kind of standard. But it is supported mainly for compatibility.
|
||||||
|
|
||||||
The browser tries to help us by mixing namespaces of JS and DOM. That's fine for simple scripts, inlined into HTML, but generally isn't a good thing. There may be naming conflicts. Also, when one reads JS code and doesn't have HTML in view, it's not obvious where the variable comes from.
|
The browser tries to help us by mixing namespaces of JS and DOM. That's fine for simple scripts, inlined into HTML, but generally isn't a good thing. There may be naming conflicts. Also, when one reads JS code and doesn't have HTML in view, it's not obvious where the variable comes from.
|
||||||
|
|
||||||
|
|
|
@ -106,7 +106,7 @@ Geometry properties are calculated only for displayed elements.
|
||||||
|
|
||||||
If an element (or any of its ancestors) has `display:none` or is not in the document, then all geometry properties are zero (or `null` for `offsetParent`).
|
If an element (or any of its ancestors) has `display:none` or is not in the document, then all geometry properties are zero (or `null` for `offsetParent`).
|
||||||
|
|
||||||
For example, `offsetParent` is `null`, and `offsetWidth`, `offsetHeight` are `0` when we created an element, but haven't inserted it into the document yet, or it (or it's ancestor) has `display:none`.
|
For example, `offsetParent` is `null`, and `offsetWidth`, `offsetHeight` are `0` when we created an element, but haven't inserted it into the document yet, or it (or its ancestor) has `display:none`.
|
||||||
|
|
||||||
We can use this to check if an element is hidden, like this:
|
We can use this to check if an element is hidden, like this:
|
||||||
|
|
||||||
|
|
|
@ -210,7 +210,7 @@ Please note: the event must have the flag `cancelable: true`, otherwise the call
|
||||||
|
|
||||||
## Events-in-events are synchronous
|
## Events-in-events are synchronous
|
||||||
|
|
||||||
Usually events are processed in a queue. That is: if the browser is processing `onclick` and a new event occurs, e.g. mouse moved, then it's handling is queued up, corresponding `mousemove` handlers will be called after `onclick` processing is finished.
|
Usually events are processed in a queue. That is: if the browser is processing `onclick` and a new event occurs, e.g. mouse moved, then its handling is queued up, corresponding `mousemove` handlers will be called after `onclick` processing is finished.
|
||||||
|
|
||||||
The notable exception is when one event is initiated from within another one, e.g. using `dispatchEvent`. Such events are processed immediately: the new event handlers are called, and then the current event handling is resumed.
|
The notable exception is when one event is initiated from within another one, e.g. using `dispatchEvent`. Such events are processed immediately: the new event handlers are called, and then the current event handling is resumed.
|
||||||
|
|
||||||
|
|
|
@ -93,7 +93,7 @@ So we should listen on `document` to catch it.
|
||||||
|
|
||||||
## Correct positioning
|
## Correct positioning
|
||||||
|
|
||||||
In the examples above the ball is always moved so, that it's center is under the pointer:
|
In the examples above the ball is always moved so that its center is under the pointer:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
ball.style.left = pageX - ball.offsetWidth / 2 + 'px';
|
ball.style.left = pageX - ball.offsetWidth / 2 + 'px';
|
||||||
|
|
|
@ -85,7 +85,7 @@ So the example above uses `document.getSelection()` to get the selected text. Yo
|
||||||
|
|
||||||
It's possible to copy/paste not just text, but everything. For instance, we can copy a file in the OS file manager, and paste it.
|
It's possible to copy/paste not just text, but everything. For instance, we can copy a file in the OS file manager, and paste it.
|
||||||
|
|
||||||
That's because `clipboardData` implements `DataTransfer` interface, commonly used for drag'n'drop and copy/pasting. It's bit beyond our scope now, but you can find its methods in the [DataTransfer specification](https://html.spec.whatwg.org/multipage/dnd.html#the-datatransfer-interface).
|
That's because `clipboardData` implements `DataTransfer` interface, commonly used for drag'n'drop and copy/pasting. It's a bit beyond our scope now, but you can find its methods in the [DataTransfer specification](https://html.spec.whatwg.org/multipage/dnd.html#the-datatransfer-interface).
|
||||||
|
|
||||||
Also, there's an additional asynchronous API of accessing the clipboard: `navigator.clipboard`. More about it in the specification [Clipboard API and events](https://www.w3.org/TR/clipboard-apis/), [not supported by Firefox](https://caniuse.com/async-clipboard).
|
Also, there's an additional asynchronous API of accessing the clipboard: `navigator.clipboard`. More about it in the specification [Clipboard API and events](https://www.w3.org/TR/clipboard-apis/), [not supported by Firefox](https://caniuse.com/async-clipboard).
|
||||||
|
|
||||||
|
|
|
@ -120,7 +120,7 @@ Rules for omitted settings:
|
||||||
|
|
||||||
## Accessing popup from window
|
## Accessing popup from window
|
||||||
|
|
||||||
The `open` call returns a reference to the new window. It can be used to manipulate it's properties, change location and even more.
|
The `open` call returns a reference to the new window. It can be used to manipulate its properties, change location and even more.
|
||||||
|
|
||||||
In this example, we generate popup content from JavaScript:
|
In this example, we generate popup content from JavaScript:
|
||||||
|
|
||||||
|
@ -257,7 +257,7 @@ Still, there are some use cases when such calls do work and can be useful.
|
||||||
|
|
||||||
For instance:
|
For instance:
|
||||||
|
|
||||||
- When we open a popup, it's might be a good idea to run a `newWindow.focus()` on it. Just in case, for some OS/browser combinations it ensures that the user is in the new window now.
|
- When we open a popup, it might be a good idea to run `newWindow.focus()` on it. Just in case, for some OS/browser combinations it ensures that the user is in the new window now.
|
||||||
- If we want to track when a visitor actually uses our web-app, we can track `window.onfocus/onblur`. That allows us to suspend/resume in-page activities, animations etc. But please note that the `blur` event means that the visitor switched out from the window, but they still may observe it. The window is in the background, but still may be visible.
|
- If we want to track when a visitor actually uses our web-app, we can track `window.onfocus/onblur`. That allows us to suspend/resume in-page activities, animations etc. But please note that the `blur` event means that the visitor switched out from the window, but they still may observe it. The window is in the background, but still may be visible.
|
||||||
|
|
||||||
## Summary
|
## Summary
|
||||||
|
|
|
@ -275,7 +275,7 @@ Arguments:
|
||||||
`targetOrigin`
|
`targetOrigin`
|
||||||
: Specifies the origin for the target window, so that only a window from the given origin will get the message.
|
: Specifies the origin for the target window, so that only a window from the given origin will get the message.
|
||||||
|
|
||||||
The `targetOrigin` is a safety measure. Remember, if the target window comes from another origin, we can't read it's `location` in the sender window. So we can't be sure which site is open in the intended window right now: the user could navigate away, and the sender window has no idea about it.
|
The `targetOrigin` is a safety measure. Remember, if the target window comes from another origin, we can't read its `location` in the sender window. So we can't be sure which site is open in the intended window right now: the user could navigate away, and the sender window has no idea about it.
|
||||||
|
|
||||||
Specifying `targetOrigin` ensures that the window only receives the data if it's still at the right site. Important when the data is sensitive.
|
Specifying `targetOrigin` ensures that the window only receives the data if it's still at the right site. Important when the data is sensitive.
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ Let's eliminate a possible source of confusion. `ArrayBuffer` has nothing in com
|
||||||
|
|
||||||
**To manipulate an `ArrayBuffer`, we need to use a "view" object.**
|
**To manipulate an `ArrayBuffer`, we need to use a "view" object.**
|
||||||
|
|
||||||
A view object does not store anything on it's own. It's the "eyeglasses" that give an interpretation of the bytes stored in the `ArrayBuffer`.
|
A view object does not store anything on its own. It's the "eyeglasses" that give an interpretation of the bytes stored in the `ArrayBuffer`.
|
||||||
|
|
||||||
For instance:
|
For instance:
|
||||||
|
|
||||||
|
|
|
@ -143,6 +143,6 @@ let results = await Promise.all([...fetchJobs, ourJob]);
|
||||||
|
|
||||||
## Summary
|
## Summary
|
||||||
|
|
||||||
- `AbortController` is a simple object that generates an `abort` event on it's `signal` property when the `abort()` method is called (and also sets `signal.aborted` to `true`).
|
- `AbortController` is a simple object that generates an `abort` event on its `signal` property when the `abort()` method is called (and also sets `signal.aborted` to `true`).
|
||||||
- `fetch` integrates with it: we pass the `signal` property as the option, and then `fetch` listens to it, so it's possible to abort the `fetch`.
|
- `fetch` integrates with it: we pass the `signal` property as the option, and then `fetch` listens to it, so it's possible to abort the `fetch`.
|
||||||
- We can use `AbortController` in our code. The "call `abort()`" -> "listen to `abort` event" interaction is simple and universal. We can use it even without `fetch`.
|
- We can use `AbortController` in our code. The "call `abort()`" -> "listen to `abort` event" interaction is simple and universal. We can use it even without `fetch`.
|
||||||
|
|
|
@ -179,7 +179,7 @@ The `integrity` option allows to check if the response matches the known-ahead c
|
||||||
|
|
||||||
As described in the [specification](https://w3c.github.io/webappsec-subresource-integrity/), supported hash-functions are SHA-256, SHA-384, and SHA-512, there might be others depending on the browser.
|
As described in the [specification](https://w3c.github.io/webappsec-subresource-integrity/), supported hash-functions are SHA-256, SHA-384, and SHA-512, there might be others depending on the browser.
|
||||||
|
|
||||||
For example, we're downloading a file, and we know that it's SHA-256 checksum is "abcdef" (a real checksum is longer, of course).
|
For example, we're downloading a file, and we know that its SHA-256 checksum is "abcdef" (a real checksum is longer, of course).
|
||||||
|
|
||||||
We can put it in the `integrity` option, like this:
|
We can put it in the `integrity` option, like this:
|
||||||
|
|
||||||
|
|
|
@ -159,7 +159,7 @@ Function `animate` accepts 3 parameters that essentially describes the animation
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
It's graph:
|
Its graph:
|
||||||

|

|
||||||
|
|
||||||
That's just like `transition-timing-function: linear`. There are more interesting variants shown below.
|
That's just like `transition-timing-function: linear`. There are more interesting variants shown below.
|
||||||
|
|
|
@ -16,7 +16,7 @@ The pattern `pattern:^Mary` means: "string start and then Mary".
|
||||||
Similar to this, we can test if the string ends with `snow` using `pattern:snow$`:
|
Similar to this, we can test if the string ends with `snow` using `pattern:snow$`:
|
||||||
|
|
||||||
```js run
|
```js run
|
||||||
let str1 = "it's fleece was white as snow";
|
let str1 = "its fleece was white as snow";
|
||||||
alert( /snow$/.test(str1) ); // true
|
alert( /snow$/.test(str1) ); // true
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue