简体   繁体   中英

Debugging console.log on object

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]

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM