The meaning of this links depends on the circumstances. Any call to a function without access (i.e., not in an object) will have this = window ( DOMWindow , if you prefer). Anything that is part of the prototype or that has been modified using apply or bind will have this as this object ("self" if you prefer).
So to illustrate. When you create an instance using the new keyword, your function automatically inherits this as itself. When you call the IETF inside it, this inside this IETF will point to the global scope.
If you want to avoid this, instead of calling testMe literally, you can always do this:
var myFunction = function() { var testMe = function() { console.log(this); } testMe.bind(this); }
Which, in turn, will this inside testMe use the object as is.
source share