繁体   English   中英

将 function 分配给变量的值而不是变量名

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM