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
Sometimes people say that `class` is a "syntax sugar" (syntax that is designed to make things easier to read, but doesn't introduce anything new) in JavaScript, because we could actually declare the same without `class` keyword at all:
122
+
Sometimes people say that `class` is a "syntax sugar" (syntax that is designed to make things easier to read, but doesn't introduce anything new), because we could actually declare the same without `class` keyword at all:
123
123
124
124
```js run
125
125
// rewriting class User in pure functions
@@ -147,7 +147,7 @@ Although, there are important differences.
147
147
148
148
1. First, a function created by `class` is labelled by a special internal property `[[FunctionKind]]:"classConstructor"`. So it's not entirely the same as creating it manually.
149
149
150
-
Unlike a regular function, a class constructor can't be called without`new`:
150
+
Unlike a regular function, a class constructor must be called with`new`:
151
151
152
152
```js run
153
153
classUser {
@@ -176,8 +176,7 @@ Although, there are important differences.
176
176
3. Classes always `use strict`.
177
177
All code inside the classconstruct is automatically in strict mode.
178
178
179
-
180
-
Also, in addition to its basic operation, the `class` syntax brings many other features with it which we'll explore later.
179
+
Besides, `class` syntax brings many other features that we'll explore later.
Copy file name to clipboardExpand all lines: 2-ui/1-document/11-coordinates/2-position-at/task.md
+8-5
Original file line number
Diff line number
Diff line change
@@ -4,12 +4,15 @@ importance: 5
4
4
5
5
# Show a note near the element
6
6
7
-
Create a function `positionAt(anchor, position, elem)` that positions `elem`, depending on `position`either at the top (`"top"`), right (`"right"`) or bottom (`"bottom"`) of the element`anchor`.
7
+
Create a function `positionAt(anchor, position, elem)` that positions `elem`, depending on `position`near `anchor`element.
8
8
9
-
Call it inside the function `showNote(anchor, position, html)` that shows an element with the class `"note"` and the text `html` at the given position near the anchor.
9
+
The `position` must be a string with any one of 3 values:
10
+
-`"top"` - position `elem` right above `anchor`
11
+
-`"right"` - position `elem` immediately at the right of `anchor`
12
+
-`"bottom"` - position `elem` right below `anchor`
10
13
11
-
Show the notes like here:
14
+
It's used inside function `showNote(anchor, position, html)`, provided in the task source code, that creates a "note" element with given `html` and shows it at the given `position` near the `anchor`.
Copy file name to clipboardExpand all lines: 2-ui/1-document/11-coordinates/article.md
+7-4
Original file line number
Diff line number
Diff line change
@@ -32,8 +32,8 @@ Main `DOMRect` properties:
32
32
33
33
Additionally, there are derived properties:
34
34
35
-
-`top/bottom` -- Y-coordinate for the top/bottom edge,
36
-
-`left/right` -- X-coordinate for the left/right edge.
35
+
-`top/bottom` -- Y-coordinate for the top/bottom rectangle edge,
36
+
-`left/right` -- X-coordinate for the left/right rectangle edge.
37
37
38
38
```online
39
39
For instance click this button to see its window coordinates:
@@ -71,11 +71,14 @@ As you can see, `x/y` and `width/height` fully describe the rectangle. Derived p
71
71
Also:
72
72
73
73
- Coordinates may be decimal fractions, such as `10.5`. That's normal, internally browser uses fractions in calculations. We don't have to round them when setting to `style.position.left/top`.
74
-
- Coordinates may be negative. For instance, if the page is scrolled down and the top `elem` is now above the window. Then,`elem.getBoundingClientRect().top` is negative.
74
+
- Coordinates may be negative. For instance, if the page is scrolled so that `elem` is now above the window, then`elem.getBoundingClientRect().top` is negative.
75
75
76
76
```smart header="Why derived properties are needed? Why does `top/left` exist if there's `x/y`?"
77
+
Mathematically, a rectangle is uniquely defined with its starting point `(x,y)` and the direction vector `(width,height)`.
77
78
78
-
The reason is that technically it's possible for `width/height` to be negative. A rectangle starts at `(x,y)` and `(width,height)` is actually the direction vector where it goes.
79
+
So the additional derived properties are for convenience.
80
+
81
+
Please note that technically it's possible for `width/height` to be negative. A rectangle starts at `(x,y)` and `(width,height)` is actually the direction vector where it goes.
79
82
80
83
Negative `width/height` may be useful for directed rectangles, e.g. to represent mouse selections with properly marked start and end.
0 commit comments