-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstatic-method.js
54 lines (43 loc) · 1.19 KB
/
static-method.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
/* static methods */
//cannot call/access on instance of the class
//static methodname(){statements}
//called on the class itself.
//used to create utility functions
//example
/*
class staticclassmethod{
static oncall(){
return "this is a static method";
}
}
//call static method
console.log(staticclassmethod.oncall());
*/
//example with two static methods
/*
class staticclassmethod{
static oncall(){
return "this is a static method";
}
static oncall2(){
return `${this.oncall()} called using another static method`;
}
}
//call static method
console.log(staticclassmethod.oncall2());
*/
//example of executing static method using instance of the class
/*
class staticclassmethod{
//declare a constructor
constructor(){
//console.log(staticclassmethod.oncall());
console.log(this.constructor.oncall());
}
static oncall(){
return "this is a static method";
}
}
//create instance for demo
const st= new staticclassmethod();
*/