-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstatic.js
More file actions
64 lines (44 loc) · 1.31 KB
/
static.js
File metadata and controls
64 lines (44 loc) · 1.31 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
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
// static = keyword that defines properrties or methods that belongs
// to a class itself rather than the object created
// from that class (class owns anything static, not the object)
//------------------------------------ example -1
// class mathUtil{
// static PI = 3.14159;
// static getDiameter(radius){
// return radius * 2;
// }
// static getcirCumference(radius){
// return 2 * this.PI * radius
// }
// static getarea(radius){
// return this.PI + radius * radius
// }
// }
// console.log(mathUtil.PI);
// console.log(mathUtil.getDiameter(12));
// console.log(mathUtil.getcirCumference(20));
// console.log(mathUtil.getarea(20));
//-------------------------------------- example - 2
class user{
static usercount = 0;
constructor(username){
this.username = username
user.usercount++;
}
sayhello(){
console.log(`hii i am ${this.username}`);
}
static myusercount(){
console.log(`currently u have ${user.usercount} users.`);
}
}
const user1 = new user('Anil')
const user2 = new user('Sunil')
const user3= new user('Sayani')
user1.sayhello()
console.log(user1.username);
user2.sayhello()
console.log(user2.username);
user3.sayhello()
console.log(user3.username);
user.myusercount();