Reputation: 133
In console.log
I received an output on object canHandle: [Function: canHandle]
and in second canHandle: [Function]
. Whats the difference in between?
const SessionEndedRequest = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'SessionEndedRequest';
}
};
returns canHandle: [Function: canHandle]
and
obj = {};
obj.canHandle = function (handlerInput) {
return handlerInput.requestEnvelope.request.type === that.type
&& handlerInput.requestEnvelope.request.intent.name === that.name;
}
retuns canHandle: [Function]
Upvotes: 2
Views: 78
Reputation: 305
it means canHandle is method of object
for example
const someObject = {
canHandle() {}
};
you can call it someObject.canHandle()
Practically those both example are same ... in first example you declared object with canHandle method.. and second example you decalerd object and later assigned canHandle metod of object
Upvotes: 1
Reputation: 1954
In the first you are assigning a function to a property called canHandle. In this case the function has a name and that name is canHandle
.
In the second you are creating an anonymous function
and assigning it to the canHandle property of your object. This is why the second function does not have a name.
Upvotes: 3