Consider the following code
Class.prototype.init = function() {
var self = this;
var onComplete = function() {
self.a.doSomethingElse(self._go);
};
console.log(this); //prints Object {...}
this.a.doSomething(onComplete); //onComplete is called inside a
};
Controller.prototype._go = function(map) {
console.log(this); //prints 'Window'
};
The question is why this is equal to window inside _go function?
The binding of the object by calling a property only applies when directly calling it. When just accessing the property and calling it later on (by e.g. passing it to a callback), the object binding is not kept.
The behaviour comes down to the following:
In your case, you could just as well pass
Controller.prototype._gosince it refers to the very same function. The solution is to useself._go.bind(self)to keep the binding.