node.js - NodeJs giving me a Object #<Object> has no method -


i have class along helper class defined:

function classa(){     this.results_array = [];     this.counter = 0;      this.requestcb = function(err, response, body){         if(err){             console.log(err);         }         else{             this.counter++;             var helper = new classahelper(body);             this.results_array.concat(helper.parse());         }     }; };  function classahelper(body){     this._body = body;     this.result_partial_array = [];     this.parse = function(){         var temp = this.parseinfo();         this.result_partial_array.push(temp);         return this.result_partial_array;     };     this.parseinfo = function(){         var info;         //get info this._body           return info     }; }; 

nodejs gives me following error:

typeerror: object #<object> has no method 'parseinfo'

i cannot figure out why can't call this.parseinfo() inside classahelper's parse method.

if can explain possible solution. or @ least, problem? tried reordering function declarations, , other ideas, no avail.

p.s. tried simplifying code stackoverflow. hepefully still makes sense :)

p.p.s first stackoverflow question. did right. :)

this scoped function inside. so, when this.parse=function(){, there new this. keep classahelper's this, have pass in or reference inside anonymous function made. following example assigns this variable outside of function , references inside function:

function classahelper(body){     this._body = body;     this.result_partial_array = [];     var self = this;     this.parse = function(){         var temp = self.parseinfo();         self.result_partial_array.push(temp);         return self.result_partial_array;     };     this.parseinfo = function(){         var info;          //get info this._body           return info;     }; }; 

further reading , other ways of doing it: why need invoke anonymous function on same line?


Popular posts from this blog