Is it possible to get this of a function from outside without calling it in Javascript? I know about the execution context idea, but my logic is, if one can bind this to a function, probably there's a way to fetch it. E.g.:
var a=function(){}; // let's imagine we have a magic function named `getThisFrom()`
getThisFrom(a); // returns `window` (or nothing, because we haven't used `bind()`)
var obj={};
var b=function(){}.bind(obj);
getThisFrom(b); // returns `obj`
Before you declare function a you could save this in a variable, i.e. var self = this;. Then return self inside a.
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