I'm new to JavaScript, and after reading "JavaScript The Good Parts" I wanted to code something for fun. I stubled upon this code snipped that I can't understand:
const actions = {
say(sessionId, context, message, cb) {
console.log(message);
cb();
},
merge(sessionId, context, entities, message, cb) {
// Retrieve the location entity and store it into a context field
const loc = firstEntityValue(entities, 'location');
if (loc) {
context.loc = loc;
}
cb(context);
},
error(sessionId, context, error) {
console.log(error.message);
},
['fetch-weather'](sessionId, context, cb) {
// Here should go the api call, e.g.:
// context.forecast = apiCall(context.loc)
context.forecast = 'sunny';
cb(context);
},
};
It is a snipped from the wit.ai node.js client. In my understanding "actions" is an object, and "say", "merge", "error", and "['fetch-weather']" are functions saved as values without key.
How is it possible to define a function without the reserved word "function"?
I also can't comprehend the "['fetch-weather']"-part.