In browser (Chrome) javascript:
var DataModler = {
Data: { Something: 'value' },
Process: function() { alert('not implemented.'); },
Render: function() { alert('not implemented.'); }
}
DataModler.Process = function() {
// do some data processing, then render it.
this.Render(); // this == Window, so an exception is thrown.
};
DataModler.Render = function() {
// render the data.
};
The problem I'm having is, if I set a breakpoint in DataModler.Process()
, this
is set to Window
. I expect this
to be set to the object that defines the function, which to my mind is DataModler
. If I implement the function within the definition of DataModler
, then this == DataModler
as I would expect.
So I suppose the question is, how can I allow a function on my object to be replaced but still have this
refer to the object on which the function is defined (DataModler
)?