Tag: 方括号

在方括号里的函数声明如何在Node.js / Javascript中工作?

第一次在Node.js中看到像这样的东西来声明函数。 总之,代码与此类似 'use strict'; const Actions = { ONE: 'one', TWO: 'two', THREE: 'three' }; class FunMap { run(action) { const map = this; map[action](); } [Actions.ONE] () { console.log("Performing action one"); } [Actions.TWO] () { console.log("Performing action two"); } [Actions.THREE] () { console.log("Performing action three"); } } var funMap = new FunMap(); funMap.run('one'); funMap.run('two'); […]