最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How can I call an exported function from itself? - Stack Overflow

programmeradmin0浏览0评论

how do I restart a Javascript function (node.js environment) from inside that has been declared like this:

exports.myfunction = function(parameter){
   //myfunction(); does not work
}

how do I restart a Javascript function (node.js environment) from inside that has been declared like this:

exports.myfunction = function(parameter){
   //myfunction(); does not work
}
Share Improve this question edited Aug 31, 2014 at 15:49 user663031 asked Aug 31, 2014 at 15:08 Igor P.Igor P. 1,4773 gold badges22 silver badges37 bronze badges 2
  • 3 Can you clarify what you mean by "restart?" I will assume you mean to recursively call it. Have you tried this.myfunction() or even exports.myfunction() ? – Antiga Commented Aug 31, 2014 at 15:11
  • Yes, I was talking about a recursive function call. – Igor P. Commented Sep 1, 2014 at 19:32
Add a ment  | 

2 Answers 2

Reset to default 6

Name it:

exports.myfunction = function myfunction(parameter) {
//                            ^^^^^^^^^^
    myfunction(); // does now work (but leads to a stack overflow obviously)
}
exports.myfunction = function(parameter){
   exports.myfunction(); // this works
}
发布评论

评论列表(0)

  1. 暂无评论