When you use .bind(this)
on the onSuccess
function, it’s making the context of this
the window
or global object – try removing it. It should be trivial to throw debug logic in there, but given the binding and explicit declaring of context it looks like you may or may not be trying to achieve something more similar to this…
// ...
receiveRequest: function(callback) {
console.log('received');
callback();
},
onSuccess: function (cb) {
console.log({'XXX: onSuccess': this});
return this.receiveRequest.bind(this, cb)
}
// ...
var requestReceivedFunc = myObj.onSuccess(function() {
console.log('my callback');
});
requestReceivedFunc();