我有这段代码,它工作得很好。是否可以将定义的函数作为参数express.post()
传递。
const exs = require('express');
const exs_r = exs.Router();
router.post('/click', function(res, res) {
//Do something
});
我想问你是否有可能这样我可以调用一个定义的函数,如下所示:
router.post('/click', def_myfunc(res, res));
<br />
function def_myfunc (res, res)
{
// do something
}
或者这听起来更合理:
router.post('/click', function(res, res) {
def_myfunc (res, res);
});
function def_myfunc (res, res)
{
// do something
}
最佳答案
只需将函数引用作为参数传递,而不是调用它
更改:
router.post('/click', def_myfunc(res, res));
至
router.post('/click', def_myfunc);
关于javascript - 是否有可能将定义的函数作为参数传递express.post(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55357400/