this: taking JavaScript out of Context
summary
Shows that a function in JavaScript can act as a constructor, method, or plain function depending on how it’s called, so the value of this is decided by the call site (look to the left of the dot). Demonstrates using bind/call/apply to lock context, replacing constructors with factory functions that use closures for private state, and using arrow functions to avoid accidental this rebinding; includes concrete examples of click handlers, setTimeout callbacks and a makePerson factory.
AI-written summary · about
chapters (16)
- 0:00Start
- 2:12F*CKING JAVASCRIPT
- 3:00When the function is called, Look to the left of the dot.
- 3:36What's really going on?
- 3:54Hint: Schrödinger's cat
- 4:45Question: How do we define methods?
- 5:09If everything is a function...
- 5:35constructor: new sayHiO
- 6:02called in three different ways
- 7:10Passing a callback to someone else?
- 7:58Can we explicitly set this?
- 10:19For example, Bespoke.js
- 11:25Functions return objects, powered by closures
- 12:02Functions: The Good Parts
- 12:46Arrow functions
- 14:28brother Look to the left of the dot.
related talks
57mUnderstanding Functions and "this" in the World of ES2018
15mJavaScript: Getting Closure
44mJavaScript - From Birth to Closure
39mJavascript for people who didn't learn Javascript
51mECMA 6 JavaScript, the Good Parts
54mPatterns for Programming in JavaScript
51mAdvanced Javascript Basics for Web Developers
29mThe JavaScript Interpreter, Interpreted
