2

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]

3
  • Please post the code that you used to produce these outputs, and state what environment you are running it in. Commented Feb 18, 2019 at 18:45
  • Probably the first function is named and the second is not, but we can only guess. Commented Feb 18, 2019 at 18:45
  • Regard the console.log approch you always can use the debugger magic word for real debugging Commented Feb 18, 2019 at 18:47

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.