How does this work in JavaScript?
You're probably wondering how the `this` keyword is set in JavaScript. There are a couple rules of thumb and things to look for that will help you understand what `this` is. We'll cover 4 different ways that methods are executed and how `this` will be bound for each. We'll also talk briefly about the differences with arrow functions
### Table of contents
Ways to call a function:
00:52 Function style overview - global object a.k.a. window in the browser
02:34 Call / Apply style overview - explicit binding
05:30 Constructor style overview - new keyword
06:14 Method style overview - dot operator
08:14 Function style demo
09:55 Call / Apply style demo
12:57 Constructor style demo
13:50 Method style demo
24:50 Class vs. prototype
29:03 function vs arrow fn
33:37 strict mode gotchas
35:15 bind
38:00 Implement myBind to see how bind might work under the hood
### Resources
MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this
Code: https://gist.github.com/cjavdev/867ba2aecb695001ebdc3613d494f185
Let's connect: https://twitter.com/cjav_dev