First time seeing something like this in Node.js for declaring functions. In short, the code is similar to this
'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');
funMap.run('three');
The above program will print
Performing action one
Performing action two
Performing action three
Is there a technical name for this type of function declaration in Node.js / Javascript?
How does this line put all these (functions declared by using the square brackets with a string constant) into property functions of the FunMap object?
const map = this;
Does the square brackets notation []
in a javascript class references the class itself?