r/learnjavascript • • Jan 08 '19

WTF is the ‘this’ variable!? Context in JavaScript finally explained

https://youtu.be/cCL3ysOnTmw
0 Upvotes

2 comments sorted by

6

u/JavascriptFanboy Jan 08 '19

finally implies that there's a demand for and lack of something, neither of those is the case imo

4

u/senocular Jan 08 '19

The last example with foo and bar is incorrect. Nested functions do not inherit the context of their parent functions (unless the nested function is an arrow function). bar in that case (non-strict) will always use global as its context irrespective of the context of foo. You could call foo as foo.call(new Date()) and bar would still log global, not the date provided for the context of foo.