this in Class Bodies

InstructorMarius Schulz

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
~ 7 years ago

Freakin awesome!

Matthias Hryniszak
~ 7 years ago

Very nice explanation.

Gisele
~ 7 years ago

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

Marius Schulzinstructor
~ 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
~ 7 years ago

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

Marius Schulzinstructor
~ 7 years ago

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

Erin Eland
~ 5 years ago

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