You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 1-js/04-object-basics/03-symbol/article.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -52,15 +52,15 @@ alert(id); // TypeError: Cannot convert a Symbol value to a string
52
52
53
53
That's a "language guard" against messing up, because strings and symbols are fundamentally different and should not occasionally convert one into another.
54
54
55
-
If we really want to show a symbol, we need to call `.toString()` on it, like here:
55
+
If we really want to show a symbol, we need to explicitly call `.toString()` on it, like here:
56
56
```js run
57
57
let id = Symbol("id");
58
58
*!*
59
59
alert(id.toString()); // Symbol(id), now it works
60
60
*/!*
61
61
```
62
62
63
-
Or get `symbol.description` property to get the description only:
63
+
Or get `symbol.description` property to show the description only:
As we can see from HTML/CSS, the slider is a `<div>` with a colored background, that contains a runner -- another `<div>` with `position:relative`.
1
2
2
-
We have a horizontal Drag'n'Drop here.
3
+
To position the runner we use `position:relative`, to provide the coordinates relative to its parent, here it's more convenient here than `position:absolute`.
3
4
4
-
To position the element we use `position:relative` and slider-relative coordinates for the thumb. Here it's more convenient here than `position:absolute`.
5
+
Then we implement horizontal-only Drag'n'Drop with limitation by width.
To drag the element we can use `position:fixed`, it makes coordinates easier to manage. At the end we should switch it back to `position:absolute`.
1
+
To drag the element we can use `position:fixed`, it makes coordinates easier to manage. At the end we should switch it back to `position:absolute` to lay the element into the document.
2
2
3
-
Then, when coordinates are at window top/bottom, we use `window.scrollTo` to scroll it.
3
+
When coordinates are at window top/bottom, we use `window.scrollTo` to scroll it.
2. At the drag start -- remember the initial shift of the pointer relative to the element: `shiftX/shiftY` and keep it during the dragging.
293
293
3. Detect droppable elements under the pointer using `document.elementFromPoint`.
294
294
295
295
We can lay a lot on this foundation.
296
296
297
-
- On `mouseup` we can finalize the drop: change data, move elements around.
297
+
- On `mouseup` we can intellectually finalize the drop: change data, move elements around.
298
298
- We can highlight the elements we're flying over.
299
299
- We can limit dragging by a certain area or direction.
300
300
- We can use event delegation for `mousedown/up`. A large-area event handler that checks `event.target` can manage Drag'n'Drop for hundreds of elements.
0 commit comments