Javascript
JavaScript Fundamentals -- The this Keyword

Function Context

PRO
Outline

Function context is the main type of context that you'll find in your application. If the context is not global, it's likely function context. There are a few ways to determine the context of a function, and we'll cover a couple methods in this video.

The first method is to find the function call, and look to the left of it. If there is a period, look to the left of the period. If that variable is an object, that object is the context of your function. If your object has nested objects, each nested object can have its own context provided one of its attributes is a function and the function is called.

The second method if by looking for the function and seeing if it's called using .call, .apply, or .bind. These are three special methods available on the prototype of every function in JavaScript. It's a way to explicitly set the context of a function that isn't an attribute on an object. If you see one of those methods being called, the object that's passed as the first argument to the function is the context.

For more information on this in JavaScript, go read this blog post.

 

I finished! On to the next chapter