![](/img/trans.png)
[英]assigning the value of function to a variable of same name in javascript
[英]Assigning a function to the value of a variable instead of the variable name
是否有可能将此 function 分配给变量名shortcut
而不是其内容?
if (this.commands[this.counter].shortcut) {
const shortcut = this.commands[this.counter].shortcut;
tinykeys(window, {
shortcut: (event) => {
this.followLink('https://twitter.com');
},
});
}
例如: shortcut
的值可以是值为“abc”的字符串,我想得到以下结果:
tinykeys(window, {
'abc': (event) => {
this.followLink('https://twitter.com');
},
});
您可以使用计算的属性名称。
[shortcut]: (event) => {
this.followLink('https://twitter.com');
},
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.