spread
?It spreads the elements of an array out over a function call. The ...
syntax is also used with object destructuring
.
Example:
const yourObject = {
name: 'Dan Levy',
city: 'Denver',
favoriteFood: '🍕'
}
const thingsYouEnjoy = ['Hiking', 'JavaScript', 'Teaching'];
// Using yourObject and thingsYouEnjoy array, set the context of this on tellUsAboutYourself and call the function.
function tellUsAboutYourself(thing1, thing2, thing3){
return `Hi! My name is ${this.name}, I live in ${this.city}, and I enjoy ${thing1}, ${thing2}, and ${thing3}. I love to eat ${this.favoriteFood}.`
}
tellUsAboutYourself.call(yourObject, ...thingsYouEnjoy);