0

const flightName = {
  airline: 'luftansa',
  itaCode: 'LH',
  book: function(flightname, text) {
    console.log(`This is ${flightname},${text}`);
  }
}

flightName.book('indigo', 'johnny');

let book1 = flightName.book;

book1.call('Johnny', 'King');

Output:

This is indigo,johnny

This is King,undefined
4
  • This seems familiar, are you watching course on Udemy by Jonas? :) Commented Jun 8, 2022 at 7:19
  • 1
    No, it's working perfectly. See developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/… Commented Jun 8, 2022 at 7:19
  • I don't think so, the output should be like This is indigo,johnny This is Johnny,King Commented Jun 8, 2022 at 7:21
  • 1
    The first argument to call is not the first argument of the called function. Read the documentation. Commented Jun 8, 2022 at 7:22

2 Answers 2

2

Try this

const flightName ={

airline: 'luftansa',

itaCode: 'LH',

book: function(flightname,text)
{

console.log(`This is ${flightname},${text}`);
}

}

flightName.book('indigo','johnny');

let book1 = flightName.book;

book1.call(this, 'Johnny','King'); 

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

Comments

2

you are calling your call funciton inccorect, call function is not supposed to work that way, as document stated: you should use it in this manner:

call()
call(thisArg)
call(thisArg, arg1)
call(thisArg, arg1, arg2)

so you need to change your code to:

book1.call(flightName,'johny', 'king');

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.