Skip to content

Commit 2acd258

Browse files
committed
minor fixes
1 parent 5a9b8a4 commit 2acd258

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

1-js/09-classes/01-class/article.md

+8-4
Original file line numberDiff line numberDiff line change
@@ -333,11 +333,13 @@ Technically, they are processed after the constructor has done it's job.
333333

334334
### Making bound methods with class fields
335335

336-
Class fields together with arrow functions are often used to create methods with fixed `this`, that always references the object.
336+
Class fields together with arrow functions can be used to create "bound" methods, with fixed `this` that always references the object.
337337

338-
As demonstrated in the chapter <info:bind>, object methods, just like any functions, have a dynamic `this`. It depends on the context of the call.
338+
As demonstrated in the chapter <info:bind> functions in JavaScript have a dynamic `this`. It depends on the context of the call.
339339

340-
So, for instance, this code will show `undefined`:
340+
So if an object method is passed around and called in another context, `this` won't be a reference to its object any more.
341+
342+
For instance, this code will show `undefined`:
341343

342344
```js run
343345
class Button {
@@ -357,7 +359,9 @@ setTimeout(button.click, 1000); // undefined
357359
*/!*
358360
```
359361

360-
There are two ways to fix this, as discussed in the chapter <info:bind>:
362+
The problem is called "losing `this`".
363+
364+
There are two ways to fix it, as discussed in the chapter <info:bind>:
361365

362366
1. Pass a wrapper-function, such as `setTimeout(() => button.click(), 1000)`.
363367
2. Bind the method to object in the constructor:

0 commit comments

Comments
 (0)