I have two files, let's call them main.js and sub.js, with a function in sub.js that is exported and called from the second file main.js but is also called from within sub.js (from another function that is exported).
The code is something like this:
Main.js:
var streak = require('./sub.js');
profile = streak.streak_broken(profile); // is called from another file
Sub.js:
// External functions
module.exports.streak_broken = function(profile) {
profile.counter = 0;
return profile;
};
module.exports.second_func = function(profile) {
// Do something
profile = streak_broken(profile); // streak_broken is not defined - how can I correct this?
return profile;
};
I could obviously make a copy of the streak_broken function and either have it as a local function further up in sub.js or put it directly into the module.exports.second_func code where it's called within sub.js but that isn't the best programming I guess.
How can I overcome that warning "streak_broken is not defined"? Your help is appreciated, thank you in advance!
Replace
profile = streak_broken(profile);
with
profile = module.exports.streak_broken(profile);