69 lines
1.6 KiB
JavaScript
69 lines
1.6 KiB
JavaScript
const lufthansa = {
|
|
airline: "Lufthansa",
|
|
iataCode: "LH",
|
|
bookings: [],
|
|
|
|
book: function (flightNumber, passengerName) {
|
|
console.log(
|
|
`${passengerName} booked a seat on ${this.iataCode}${flightNumber}`
|
|
);
|
|
this.bookings.push({
|
|
flight: `${this.iataCode}${flightNumber}`,
|
|
passengerName,
|
|
});
|
|
},
|
|
};
|
|
|
|
const book = lufthansa.book;
|
|
|
|
const wizzair = {
|
|
airline: "Wizzair Air Hungary",
|
|
iataCode: "WZ",
|
|
bookings: [],
|
|
};
|
|
|
|
// binding der Methode book aus dem lufthasa Objekt dem wizzair Objekt
|
|
const bookEW = book.bind(wizzair);
|
|
// Verwendung der book Methode im wizzair Objekt, und ihre Ausführung
|
|
bookEW(663, "David A.");
|
|
|
|
console.log(wizzair.bookings);
|
|
|
|
const bookWZ52 = book.bind(wizzair, 52);
|
|
bookWZ52("David Aster");
|
|
bookWZ52("Joanne Aster");
|
|
console.log(wizzair.bookings);
|
|
|
|
lufthansa.planes = 300;
|
|
lufthansa.buyPlane = function () {
|
|
console.log(this);
|
|
this.planes++;
|
|
|
|
console.log(this.planes);
|
|
};
|
|
|
|
// console.log(lufthansa.planes);
|
|
lufthansa.buyPlane();
|
|
|
|
// document
|
|
// .querySelector(".buy")
|
|
// .addEventListener("click", lufthansa.buyPlane.bind(lufthansa));
|
|
|
|
// Partial Applikation
|
|
const addTAX = (rate, value) => value + rate * value;
|
|
const addVAT = addTAX.bind(null, 0.22);
|
|
// addTAX = (rate, value) => value + 0.22 * value;
|
|
// Mehrwertsteuer wird da immer 22% sein
|
|
console.log(addVAT(120));
|
|
|
|
// Das Gleiche kann man auch mit einer Methode erreichen, die eine Methode zurück gibt
|
|
const addTAX1 = function (rate) {
|
|
return function (value) {
|
|
return value + value * rate;
|
|
};
|
|
};
|
|
|
|
const addVAT1 = addTAX1(0.22);
|
|
console.log(addVAT1(100));
|
|
console.log(addVAT1(120));
|