-
Notifications
You must be signed in to change notification settings - Fork 1
/
clousers.js
75 lines (51 loc) · 1.48 KB
/
clousers.js
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
//this keyword
var football = new stadium("camp nou", "messi", "752", "256");
function stadium(sname, bestplayer, goals, assists) {
this.sname = sname;
this.bestplayer = bestplayer;
this.goals = goals;
this.assists = assists;
}
console.log(stadium);
console.log(football);
//closures
const r = require("readline-sync");
var manchester_city = () => {
var titles = 4;
let num = r.question("have you won the title in 2021? (Y/N)");
var manager = () => {
if (num == 'Y' || num == 'y')
titles++;
console.log("your total no of titles is ", titles);
}
return manager;
}
const innerfunc = manchester_city();
innerfunc();
//bind function ---> call and apply
const arsenal = {
fa_cup: 13,
premierleague: 4,
firstName: "Mikel",
lastName: "Arteta",
manager1: function (firstName, lastName) {
return firstName + " " + lastName;
},
totaltitles: function () {
console.log("total no of titles are", this.fa_cup + this.premierleague);
}
}
const chelsea = {
fa_cup: 5,
premierleague: 3
}
const liverpool = {
fa_cup: 8,
premierleague: 20
}
arsenal.totaltitles.call(chelsea);
arsenal.totaltitles.call(liverpool);
console.log(arsenal.manager1.call(chelsea, "thomas", "tuchel"));
console.log(arsenal.manager1.call(liverpool, "Jurgen", "klopp"));
console.log(arsenal.manager1.apply(chelsea, ["thomas", "tuchel"]));
console.log(arsenal.manager1.apply(liverpool, ["Jurgen", "klopp"]));