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.