Javascript 如何在Node JS中本地和外部调用函数(从两个不同的文件调用)

Javascript 如何在Node JS中本地和外部调用函数(从两个不同的文件调用),javascript,node.js,function,Javascript,Node.js,Function,我有两个文件,我们称它们为main.js和sub.js,sub.js中有一个函数,从第二个文件main.js导出和调用,但也从sub.js中调用(从导出的另一个函数) 代码如下所示: Main.js: var streak = require('./sub.js'); profile = streak.streak_broken(profile); // is called from another file Sub.js: // External functions module.expor

我有两个文件,我们称它们为main.js和sub.js,sub.js中有一个函数,从第二个文件main.js导出和调用,但也从sub.js中调用(从导出的另一个函数)

代码如下所示:

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;
};
很明显,我可以复制streak_break函数,将其作为sub.js中的本地函数,或者将其直接放入module.exports.second_func代码中,在sub.js中调用它,但我想这不是最好的编程

我如何克服“条纹未定义”的警告?感谢您的帮助,提前谢谢

更换

profile = streak_broken(profile);


谢谢,我以前试过出口。streak_Break(个人资料)但从未试过这个。在试图找到这个问题的答案时,我遇到了几篇文章建议使用而不是module.exports,而不是单独使用exports,因此我从未尝试过。非常感谢您的快速帮助,不客气!如果导出多个函数,则可以使用
exports.func1
exports.func2
。。。。如果只导出一个函数,则需要编写
module.exports=func1
profile = module.exports.streak_broken(profile);