Question from the Javascript test

What are the call and apply keywords used for in Javascript?

Hard

What are the call and apply keywords used for?

Author: Jean-marie CléryStatus: PublishedQuestion passed 1871 times
Edit
0
Community Evaluations
developer avatar
Ambiguous
jonh
26/01/2024
pas de fin a la question ?
developer avatar
hugo
01/03/2023
Apply ne prend pas forcément un second argument en paramètre. const user = { name: "Pedro", sayHi(){ return `hi my name is ${this.name}` } } const otherUser = { name: "Bob" } console.log(user.sayHi.apply(otherUser)) // 1 seul paramètre et c'est pas un tableau.
developer avatar
hugo
01/03/2023
Après c'est pas marqué sur la documentation que ca fonction sans tableau avec un seul argument. Donc mon objet "otherUser" est-il un tableau ? Peut-être. Mais il n'empêche que ça marche quand même très bien avec un seul argument.
developer avatar
Auteur anonyme
16/03/2023
Je vais modifier la question pour que soit plus clair ! Merci pour ton retour Hugo !