Saturday 27 May 2017

How to change scope back to original function after calling a “local” function within module.exports in Node.JS

I am trying to call another local function 'MessageScoring' within another function 'NextMessageCalculation' which are both in module.exports, however I am having trouble with getting the scope to change back. The function successfully calls the other local function, however the scope is then changed and variables in the previous scope all return undefined now. How would I fix this or is there a better way to call the local function to avoid this?

module.exports = {
   MessageScoring: function()...

   NextMessageCalculation: function(){
              console.log(d[i]['id']); //returns correct value
              var score = module.exports.MessageScoring(doc[i].attr_list,user_data);
              console.log(d[i]['id']); //returns undefined now
   } 
}



via Austen Novis

No comments:

Post a Comment