I'm writing an application in Node, for which I've got a function which I extend with some methods.
function WsClient(key, secret, url) {
// here some init code
}
WsClient.prototype.addLisener = function(id, listener) {
// code
}
WsClient.prototype.request = function(action, data) {
// code
};
WsClient.prototype.getpositions = function() {
this.request('/api/v1/positions', {});
};
let wsclient = new WsClient(KEY, SECRET);
wsclient.getpositions();
setInterval(() => {console.log('CALLING FROM INSIDE INTERVAL'); wsclient.getpositions()}, 1111);
But to my surprise I now get a TypeError in the getpositions() method, saying this.request is not a function
. The code looks good to me, but coming from Python/php I'm unsure what I'm doing wrong here.
Does anybody know what mistake I'm making here?
[EDIT]
I just found out that it is successfully called multiple times before it fails with this error. Furthermore, it is successfully called from various other methods as well, which first succeed, and finally it fails on one of the calls with this error. I'm unsure why this happens. Any idea?