java - Class construction in node.js using this -


im new node , js

i have utilities class build , can initiated utilities.newobject , used utilities.somemethod(args, callback):

exports.newobject = function(){   return new utilities(); }  var utilities = function(){    this.method1 = function(args, callback){     //   }    this.method2 = function(args, callback){     //stuff   }    this.method3 = function(args, callback){     //stuff   } } 

my problem: there way use method1 in method 2? works call directly in method, doesn't if called in function, running in method:

exports.newobject = function(){   return new utilities(); }  var utilities = function(){    this.method1 = function(args, callback){     somecallbackfunction(args, function(result){       this.method2(args) // not work     });   }    this.method2 = function(args, callback){     this.method1(args) //  works   }    this.method3 = function(args, callback){     //stuff   } } 

any advice novice?

try out:

exports.newobject = function(){     return new utilities(); }  var utilities = function(){     this.method1 = function(args, callback){         var self = this;         somecallbackfunction(args,function(){                    self.method2(args,function(){             });         });       }     this.method2 = function(args, callback){        this.method1();        }     this.method3 = function(args, callback){        //stuff     } } 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -