Why use parentheses when returning in JavaScript?

题意:为什么在 JavaScript 中返回时使用括号?

问题背景:

In the Restify framework code I found this function:

在 Restify 框架代码中,我发现了这个函数:

function queryParser(options) {

    function parseQueryString(req, res, next) {
        // Some code goes there
        return (next());
    }
    return (parseQueryString);
}

Why would the author write return (next()); and return (parseQueryString);? Does it need parentheses there and if so, why?

为什么作者会写 return (next());return (parseQueryString);?在这里需要括号吗,如果需要,原因是什么?

问题解决:

It doesn't need to be that way, but it's valid JavaScript code. Actually it's quite uncommon to see such syntax. I guess it's a personal preference of the author.

这样写并不是必须的,但它是有效的 JavaScript 代码。实际上,这种语法很少见。我想这可能是作者的个人偏好。

猜你喜欢

转载自blog.csdn.net/suiusoar/article/details/143482400