Call, Apply und Bind
call()-Methode
call()-Methodeconst lufthansa = {
airline: 'Lufthansa',
iataCode: 'LH',
bookings: [],
book(flightNum, name) {
console.log(
`${name} booked a seat on ${this.airline} flight ${this.iataCode}${flightNum}`
);
this.bookings.push({ flight: `${this.iataCode}${flightNum}`, name });
}
};
lufthansa.book(971, 'Levin');
lufthansa.book(972, 'Martha');
console.log(lufthansa);
// Copying the book method would be a bad practice
const eurowings = {
airline: 'Eurowings',
iataCode: 'EW',
bookings: []
};
const book = lufthansa.book;
book(973, 'Steven');apply()-Methode
apply()-Methodebind()-Methode
bind()-MethodeBeispiel mit Event-Listeners
Last updated