Hi guys,

I have a doubt if I have this a.js:

// a.js
module.exports = {
  someFunction: function() {
    function innerFunction() {
      //code here
    }
    innerFunction();
  }
}

and this other one b.js:

// b.js
function outterFunction() {
//code here
}

module.exports = {
  someFunction: function() {
    innerFunction();
  }
}

NodeJS files are cached whenever we require them, that's so far so good, 
now my question is does the innerFunction in file a.js its also cached? or 
everytime I call 
require('a.js').someFunction() the function innerFunction is redefined?

I would like to know about this because in case always the function is 
redefined I prefer to use the command pattern to define modules in node and 
then just attach what I just defined to module.exports like this, with this 
way all the functions will be cached by the mechanism of require (in case 
the function is always redefined in the file a.js):

// c.js
(function(){
  function outterFunction() {
    // code here
  }

  function someFunction() {
    outterFunction();
  }
})();

module.exports = {
  someFunction: someFunction
}

Thanks in advance guys.

-- 
Job board: http://jobs.nodejs.org/
New group rules: 
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/c2b5c9fd-beec-46c2-a63c-5800d7a5188f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to