如何使用常量来调用某物?

huangapple go评论61阅读模式
英文:

How can I use a constant to call on something?

问题

When I try to add a variable into a calling on a required value.
我尝试将一个变量添加到对所需值的调用中。

I am trying to input the constant cookieinfo into calling on a cookie value.
我正在尝试将常量cookieinfo输入到对cookie值的调用中。

const cookieinfo = "bot" + result.bot

const config = require('/Users/Owner/Downloads/RankBloxCode/config');
const bloxy = require('bloxy');
const robloxClient = new bloxy.Client({
    credentials: {
        cookie: config.cookieinfo
    }
});

//Input
result.bot = abc
//Output
output = config.botABC
英文:

When I try to add a variable into a calling on a required value.
I am trying to input the constant cookieinfo in to calling on a cookie value.

const cookieinfo = "bot" + result.bot

const config = require('/Users/Owner/Downloads/RankBloxCode/config');
const bloxy = require('bloxy');
const robloxClient = new bloxy.Client({
    credentials: {
        cookie: config.cookieinfo
    }
});

//Input
result.bot = abc
//Output
output = config.botABC

答案1

得分: 0

除非我误解了你的问题,你必须使用方括号表示法来处理动态键(点表示法仅适用于静态键)。

所以 config.cookieinfo 必须是 config[cookieinfo]

英文:

unless I'm misunderstanding your problem, you must use bracket notation for dynamic keys (dot notation only works with static keys).

so config.cookieinfo has to be config[cookieinfo]

huangapple
  • 本文由 发表于 2023年5月14日 10:54:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/76245622.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定