I'm confused as to what the problem is with context in a JS constructor. Within the ctor I have a function declared. Before the call to that function this
is set to the context of the ctor. Inside the function the value of this
is set to window
. I don't understand why. In the HTML the ctor is called with 'new'.
function MyCtor() {
var myFunc = function() {
debugger; // #2
// code for myFunc
}
debugger; // #1
myFunc();
debugger; // #3
}
At debugger #1, this
is set to MyCtor
. At #2 this
is window
. And at #3 it is back to MyCtor
.
I'm sure I'm missing something basic here, but I've read a lot on scope and context; obviously not enough.