调试对象上的console.log
在console.log
,我收到了对象canHandle: [Function: canHandle]
和第二个canHandle: [Function]
的输出。两者之间的区别是什么?
const SessionEndedRequest = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'SessionEndedRequest';
}
};
返回canHandle: [Function: canHandle]
和
obj = {};
obj.canHandle = function (handlerInput) {
return handlerInput.requestEnvelope.request.type === that.type
&& handlerInput.requestEnvelope.request.intent.name === that.name;
}
retuns canHandle: [Function]
在第一个中,您将一个函数分配给名为canHandle的属性。在这种情况下,该函数具有名称,该名称为canHandle
。
在第二步中,您将创建一个anonymous function
并将其分配给对象的canHandle属性。这就是第二个函数没有名称的原因。