-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass-static-function-inside.js
More file actions
39 lines (32 loc) · 1.02 KB
/
Copy pathclass-static-function-inside.js
File metadata and controls
39 lines (32 loc) · 1.02 KB
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
class Student {
name;
yob;
place;
contestWin;
constructor(name, yob, place, contestWin) {
this.name = name;
this.yob = yob;
this.place = place;
this.contestWin = contestWin;
}
getDetails() {
return `Class-A student leader name is ${this.name} from ${this.place}. He/She is ${new Date().getFullYear() - this.yob} years old.`
}
static totalContestPrize(...args) {
const totalPrize = args.reduce((total, item) => {
return total + item.contestWin
}, 0);
console.log(`Our school achieved total ${totalPrize} prizes`)
}
}
const classA = new Student('Lek', 1989, 'Kochi', 6)
const classB = new Student('Ranju', 1989, 'Kochi', 8)
console.log(classA.getDetails())
console.log(classB.getDetails())
Student.totalContestPrize(classA, classB);
/*
* ----------------------------------------------------------------------
* Static class methods are defined on the class itself.
* You cannot call a static method on an object, only on an object class.
* ----------------------------------------------------------------------
*/