node.js - Pass a block variable to a callback function that has already arguments -


this callback:

function evaluateserviceresponse(err, response){   db.answercollection.insert({id: response["serviceanswer"]["id"]}); //problem line  } 

this callback-user:

mysoapclient.invokeservicemethod(jsonrecords,this.evaluateserviceresponse); 

here whole code. inside process create block reference database:

process(function(){   ...   let db=null;   db = mongoclient.connect(connectionurl);    //do whatever create jsonrecords   mysoapclient.invokeservicemethod(jsonrecords,this.evaluateserviceresponse);   ... }); 

the invokeservicemethod talks service calls callback passing service response.

how db reference callback evaluateserviceresponse?

thanks.

use closure :

function evaluateserviceresponse(db){   return function(err, response){   db.answercollection.insert({id: response["serviceanswer"]["id"]}); //problem line } } 

and use like:

 mysoapclient.invokeservicemethod(jsonrecords,this.evaluateserviceresponse(db)); 

Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -