Call and apply is that call requires the arguments to be passed in one-by-one, and apply takes the arguments as an array.
A for array and C for comma.”
function longerSummary(genre, year) {
console.log(
`${this.title} was written by ${this.author}. It is a ${genre} novel written in ${year}.`
)
}
longerSummary.call(book, 'dystopian', 1932)
longerSummary.apply(book, ['dystopian', 1932])
Functions vs arrowArrow functions do not have their own this
binding. Instead, they go up to the next level of execution.
const whoAmI = {
name: 'Leslie Knope',
regularFunction: function () {
console.log(this.name)
},
arrowFunction: () => {
console.log(this.name)
},
}
whoAmI.regularFunction() // "Leslie Knope"
whoAmI.arrowFunction() // undefined
https://www.taniarascia.com/this-bind-call-apply-javascript/
Leave a Reply