-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass.js
174 lines (133 loc) · 3.02 KB
/
class.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/*class Emp {
constructor(empName, empAge) {
this.empName = empName
this.empAge = empAge
}
displayEmp(name, age) {
this.empName = name
this.empAge = age
console.log(this.empName +' >> '+ this.empAge)
}
}
let objEmp = new Emp("John", 34)
objEmp.displayEmp('Peter', 44)
objEmp.displayEmp('Heter', 34)
objEmp.displayEmp('Peter323', 44)
objEmp.displayEmp('Heter2323', 34)*/
/*
class User {
constructor(name) { this.name = name; }
sayHi() { console.log(this.name); }
}
// class is a function
console.log(typeof User); // function
// ...or, more precisely, the constructor method
console.log(User === User.prototype.constructor); // true
// The methods are in User.prototype, e.g:
console.log(User.prototype.sayHi); // the code of the sayHi method
// there are exactly two methods in the prototype
console.log(Object.getOwnPropertyNames(User.prototype)); */
/*
let User = class {
SayHello (){
console.log("Hello World")
}
}
console.log(new User().SayHello())*/
/*
function buildClass(className) {
return class {
SayHello(){
console.log(className)
}
}
}
let dynamicClass = buildClass('Hello')
new dynamicClass().SayHello()*/
/*
class Emp {
constructor(empName) {
this.empName = empName;
}
get () {
return this.empName
}
set(empname) {
this.empName = empname
}
displayName(){
console.log(this.empName)
}
}
let newEmp = new Emp("John")
newEmp.displayName()
newEmp.set("Peter")
newEmp.displayName()
newEmp.set("PeterHencil")
console.log(newEmp.get())
*/
/*
class User {
['Hello' + 'World']() {
console.log("Hello World");
}
}
new User().HelloWorld();*/
/*
class Button {
constructor(value) {
this.value = value;
}
//Method
click() {
console.log(this.value);
}
//Properties
clickAgain = () => {
console.log(this.value);
}
}
let button = new Button("hello");
setTimeout(() => {
button.click()
},
1000);
setTimeout(button.clickAgain)*/
/*
class User {
constructor(name, place){
this.name = name
this.place = place
}
displayName(){
console.log(this.name +" >> "+ this.place)
}
}
class Student extends User {
constructor(name, age, place) {
super(name, place)
this.age = age
}
displayName(){
super.displayName()
console.log(this.age)
}
}
let student1 = new Student("John Peter", 23, "Kerala")
student1.displayName()
//console.log(student1.name +" >> "+ student1.age +" >> "+ student1.place)*/
//Static Properties and functions
class User {
static name = "John Peter"
static displayName() {
console.log("This is Static Function")
}
}
console.log(User.name)
User.displayName()
class Helper {
add(a, b) {
return a + b
}
}
Helper.add(5,6)