3 ms·
I found it pedantic as well. 'This' really is just the object to the left of the dot, unless 'new' is used to invoke the function with a brand new 'this' object
by Udik 10y ago
I found it pedantic as well. 'This' really is just the object to the left of the dot, unless 'new' is used to invoke the function with a brand new 'this' object. Functions called without a 'left-of-the-dot' argument, not having a 'this' injected, just see that of the global scope (Window). Call and apply allow to explicitly inject the 'this' object. That pretty much sums up at least 80% of the chapter.
- rashkov 10y agoAs kabes pointed out above, there are more exceptions than the ones you mention. Don't forget bind, call/apply, strict mode, and arrow functions. "this" is just a reference to the function context. Function context has a strong definition in programming languages. Saying that it's the stuff to the "left-of-dot" modulo a bunch of exceptions is sort of missing the forest for the trees, in my opinion. Left-of-dot is a great way to introduce the concept but function context is so much more than just that.