Say I need to stick some methods onto an object using the this keyword, but inside of another function, or inside of a promise (for some reason this is undefined in that context).
Is there a convention for doing this? This is a semantic question as I know all I need to do is essentially var cachedThis = this; to make it work.
Is there an existing pattern I can use that a future developer might recognize?
There is one that I am using, and I have seen it being used around quite a lot.
'let me take a selfie...'
var self = this;
I am not sure if this qualifies to be called convention.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With