javascript - Properly Scoping my Reference -
i have node app creates soap client create several api calls. each phone call starts login()
client created. rather create client each successive call, i'd store away , reuse same client subsequent calls happen in callbacks. i'm struggling scoping.
i have module.exports
set function returns object:
return { soapclient: null, /** * establishes connection client api & authenticates. * * @param {object} args object containing * @param {function} callback [description] * @return {[type]} [description] */ login: function( username, password, callback ) { var url = datasources.api.baseurl; // create soap client we'll utilize phone call api datasources.api.module.createclient( url, function( err, soapclient ) { // store off client future calls. // ---> problem <--- // this.soapclient = soapclient; // authenticate var authargs = {...}; soapclient.login( authargs, function( err, result ) { // authenticate }); }); }, ... additional functions ... }
how can store soapclient
passed createclient()
callback can "cached" in object property , reused other functions in model?
javascript node.js scope
No comments:
Post a Comment