I saw this sample code and do not understand the syntax:
const newSessionHandler = {
LaunchRequest() {
this.handler.state = "ASKMODE";
this.emit(":ask", "Welcome to Custom Alexa skill, are you ready to begin?");
}
};
Here LaunchRequest
is not a function call and it is not a function definition as there is no keyword function
. So what is it?
I understand the following format in which LaunchRequest
is a key:
const newSessionHandler = {
LaunchRequest: function() {
this.handler.state = "ASKMODE";
this.emit(":ask", "Welcome to Custom Alexa skill, are you ready to begin?");
}
};
Another question: Are LaunchRequest
, NewSession
, Unhandled all built-in events in nodejs alexa-sdk? Is there a document for all the built-in events in alexa-sdk?
Welcome to ES 6, new way to declare functions within Objects.
It is implicitly adding function keyword over there.
Learn more on ES6 function declarations, and specifically the difference between using Explicit 'function' and () => {}
, where you will have problem with 'this' keyword.
In the new form of function declaration ()=>{}, this will refer to its parent scope and not the calling function.