Understand JavaScripts this keyword within Prototypes

Share this video with your friends

Send Tweet

It may be confusing to understand how the this keyword is used when accessing a method through the prototype chain. For example if one object has a method with this used and is called through a linked object, what is the context? We’ll play around with this usage and show when context changes.

alwin
alwin
~ 6 years ago

I went through this clip three times to fully understand what happened.

Fisker Karma
Fisker Karma
~ 6 years ago

I watched it twice, took a break and watched it twice again.

Ilham Wahabi
Ilham Wahabi
~ 6 years ago

Its confused to use foo, bar, and baz

Matt
Matt
~ 6 years ago

This content is basically derived from here https://github.com/getify/You-Dont-Know-JS/blob/master/this%20%26%20object%20prototypes/ch5.md#prototypal-inheritance

Sergey Ryabov
Sergey Ryabov
~ 4 years ago

Isn't Bar function has Foo's context after assigning Foo's prototype to it? So that we basically passing Foo's context (/this) back to Foo in Bar?