首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >JavaScript将object[method]展开为object.method以调用object.method()

JavaScript将object[method]展开为object.method以调用object.method()
EN

Stack Overflow用户
提问于 2014-07-12 19:47:04
回答 1查看 37关注 0票数 0

如果是method = "post",我如何使rest[method]扩展到rest.post(uri, body).then(..

代码语言:javascript
运行
复制
function proxyUrl() {
    return function(req, res, next) {
        proxyFound = url.some(function (element) {
            if (req.url == element) {
                method = req.method.toLowerCase();
                body = req.body;
                //get host to prozy to
                var host;
                arrayProxies.some(function (hostName) {
                    if (proxyList[hostName] == element) {
                        host = hostName;
                        return true;
                    }
                });
                //Make Call...do proxy
                uri = 'https://'+host;
                console.log(method);
                rest[method](uri, body).then(
                    function(response) {
                        res.send(response);
                    }, function(error) {
                        res.send(error.statusCode, error);
                    });

            }
            return true;
        });
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-07-12 19:52:48

如果是method = "post",那么它就是rest[method](uri, body).then(… --就像代码中有它一样。括号表示法与往常一样适用于方法调用。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24716691

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档