-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path8-Call-and-Apply-Method.js
More file actions
55 lines (44 loc) · 1012 Bytes
/
8-Call-and-Apply-Method.js
File metadata and controls
55 lines (44 loc) · 1012 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
"use strict";
const lufthansa = {
airLine: "Lufthansa",
iataCode: "LH",
bookings: [],
// book: function () {},
book(flightNum, name) {
console.log(
`${name} booked a seat on ${this.airLine} flight ${this.iataCode}${flightNum}`
);
this.bookings.push({
flight: `${this.airLine} flight ${this.iataCode}`,
name,
});
},
};
lufthansa.book(239, "Umair");
lufthansa.book(635, "Umair T.");
console.log(lufthansa);
const eurowings = {
airLine: "Eurowings",
iataCode: "EW",
bookings: [],
};
const book = lufthansa.book;
// Does not work
// book(23, 'Ali');
// Call Method
book.call(eurowings, 23, "Sarah");
console.log(eurowings);
book.call(lufthansa, 239, "Mary");
console.log(lufthansa);
const swiss = {
airLine: "Swiss Airlines",
iataCode: "LX",
bookings: [],
};
book.call(swiss, 583, "Mary");
console.log(swiss);
// Apply method
const flightData = [583, 'George'];
book.apply(swiss, flightData);
console.log(swiss);
book.call(swiss, ...flightData);