this in Class Bodies

Share this video with your friends

Send Tweet

Within the constructor of a class, this refers to the newly created object. Within a method, however, this might refer to another value if the method is called as an ordinary function. Just like any other object method, class methods can lose their intended receiver this way.

This lesson shows different approaches to solving this problem either by binding class methods or by using class fields with arrow functions instead.

Vamshi
Vamshi
~ 7 years ago

Freakin awesome!

Matthias Hryniszak
Matthias Hryniszak
~ 7 years ago

Very nice explanation.

Gisele
Gisele
~ 7 years ago

Hi, what is this babel | node? It's from node?

Marius Schulz
Marius Schulz(instructor)
~ 7 years ago

@Gisele: I'm using a Unix Pipeline to feed the output generated by npm run babel directly into node to execute the transpiled JavaScript code.

Gisele
Gisele
~ 7 years ago

So it's some kind of comand-line? Like prompt (windows) or git bash?

Marius Schulz
Marius Schulz(instructor)
~ 7 years ago

@Gisele: | is shell syntax that can be used on the command line, yes.

Erin Eland
Erin Eland
~ 5 years ago

@Marius, great course, love how specific and concise this is! (pun intended)