[英]Debugging console.log on object
In console.log
I received an output on object canHandle: [Function: canHandle]
and in second canHandle: [Function]
. 在
console.log
我收到对象canHandle: [Function: canHandle]
和第二个canHandle: [Function]
。 Whats the difference in between? 两者之间有什么区别?
const SessionEndedRequest = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'SessionEndedRequest';
}
};
returns canHandle: [Function: canHandle]
返回
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]
调整
canHandle: [Function]
In the first you are assigning a function to a property called canHandle. 在第一个示例中,您将一个函数分配给名为canHandle的属性。 In this case the function has a name and that name is
canHandle
. 在这种情况下,该函数具有一个名称,该名称为
canHandle
。
In the second you are creating an anonymous function
and assigning it to the canHandle property of your object. 在第二个步骤中,您将创建一个
anonymous function
并将其分配给对象的canHandle属性。 This is why the second function does not have a name. 这就是第二个函数没有名称的原因。
it means canHandle is method of object 这意味着canHandle是对象的方法
for example 例如
const someObject = {
canHandle() {}
};
you can call it someObject.canHandle() 你可以称它为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 实际上,这两个示例是相同的...在第一个示例中,您使用canHandle方法声明了对象。.在第二个示例中,您对对象进行了除垢,然后分配了对象的canHandle方法
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.