this not bound until the function is called and independent of how the function is called. You might think of it as an extra parameter implicitly passed to the function.
In this case, the problem is that you are calling internalFunction with internalFunction() . This value is set either by calling the function as a method (as in foo.bar() , or foo["bar"]() ), or by setting this explicitly via call() or apply() . Your call does not make this return to the global object.
The easiest way to achieve what you want in this case, while keeping internalFunction private, is to keep a reference to this inside the constructor function:
var Constructor = function() { var thisObj = this; var internalFunction = function () { return thisObj === window; }; thisObj.myMethod = function () { alert(internalFunction()); }; }
Tim down
source share