It's good to practice 'this' like this but there's always a whole bunch of other scenarios that might still trip people up. The best thing to do is to have some theory to solidify the understanding:
'this' is an object created for every Execution Context that is created (on program startup and on every function invocation).
'this' can change based on how/where the function is called/invoked.
There are four patterns of invoking functions that define the context of the function being called:
function invocation (e.g. says())
method invocation (e.g. call.says())
constructor invocation pattern (when you call a constructor function with the 'new' keyword - e.g. var person = new Caller())
apply invocation pattern (when you provide your own context while calling the function with say.call() or say.apply(), or if you explicitly bind the context with say.bind())
Here's a really good article about these four patterns (read until the React part): reactkungfu.com/2015/07/why-and-ho...
Couldn't agree more. Thanks so much for providing an overarching concept around 'this'. That could've been a better opening for 'this' post (pun intended).
1) 'this' is an object created for every Execution Context that is created (on program startup and on every function invocation).
I think it's also important to mention that arrow functions don't get own this keyword - they can use this keyword of their closest regular function parent
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
It's good to practice 'this' like this but there's always a whole bunch of other scenarios that might still trip people up. The best thing to do is to have some theory to solidify the understanding:
Couldn't agree more. Thanks so much for providing an overarching concept around 'this'. That could've been a better opening for 'this' post (pun intended).
1) 'this' is an object created for every Execution Context that is created (on program startup and on every function invocation).
I think it's also important to mention that arrow functions don't get own
this
keyword - they can usethis
keyword of their closest regular function parent