update post: What is this inside foo.bar()?

This commit is contained in:
2020-04-03 09:42:05 +05:30
parent 05ebb7fe45
commit a7ac1e5c47
+1 -1
View File
@@ -46,7 +46,7 @@ Effectively -
One example of this is rewriting `foo.bar()` using a intermediate variable - ` fn = foo.bar; fn()`. One example of this is rewriting `foo.bar()` using a intermediate variable - ` fn = foo.bar; fn()`.
Now. if `bar` was referencing other values from foo using `this`, those values will become undefined or resolve to a wrong variable. Now, if `bar` was referencing other values from foo using `this`, those values will become undefined or resolve to a wrong variable.
🧠 This is exactly the reason why passing methods as callback changes the value of `this` (passed within it). Instead of calling a method directly, callback is passed as a function and called later by some other code. 🧠 This is exactly the reason why passing methods as callback changes the value of `this` (passed within it). Instead of calling a method directly, callback is passed as a function and called later by some other code.