@@ -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
343345class 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
3623661 . Pass a wrapper-function, such as ` setTimeout(() => button.click(), 1000) ` .
3633672 . Bind the method to object in the constructor:
0 commit comments