Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从node.js中的被调用函数访问调用函数?_Node.js_Express - Fatal编程技术网

如何从node.js中的被调用函数访问调用函数?

如何从node.js中的被调用函数访问调用函数?,node.js,express,Node.js,Express,我想知道在子函数中调用返回父函数 app.get('/path', function(req, res, next) { var result = child('test_Val', next); return res.send(200); }); function child(arg1, next) { if (condition) { //I want to call return parent function with ne

我想知道在子函数中调用返回父函数

app.get('/path', function(req, res, next) {
        var result = child('test_Val', next);

        return res.send(200);
    }); 

function child(arg1, next) {
   if (condition) {
      //I want to call return parent function with next() here.
   }
}
有可能吗?

在前言中,你真的不应该这样做。你的问题几乎肯定意味着你在设计一些错误的东西,这样做将禁用v8中的大量优化

但你可以做到

在函数内部,可以使用神奇变量
arguments
。这是一个类似的数组,包含该函数的所有参数。此外,它还有一些有趣的属性,其中之一就是
被调用方
。这是对您当前使用的函数的引用。它还有一些有趣的特性。一个是
参数
,它指向原始的
参数
对象。我们要找的是
调用者

因此,在函数内部,
arguments.callee.caller
是对调用函数的引用

app.get('/path', function(req, res, next) {
        var result = child('test_Val', next);

        return res.send(200);
    }); 

function child(arg1, next) {
   if (condition) {
      //I want to call return parent function with next() here.
   }
}

再说一遍,请不要这样做。你应该问另一个更详细的问题,以便有人能帮助你解决真正的问题。

你不是指“父”和“子”函数,而是指“调用”和“调用”函数。不,从被调用函数中看不到调用函数。如果你想这么做,这意味着你的逻辑有问题。“调用返回父函数”是什么意思?(需要注意的是,
callee
在严格模式下是不允许的。)