-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass.js
More file actions
32 lines (26 loc) · 850 Bytes
/
Copy pathclass.js
File metadata and controls
32 lines (26 loc) · 850 Bytes
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
//Before ES6 function
// function Student(name, rollNumber, age, subject) {
// this.name = name;
// this.rollNumber = rollNumber;
// this.age = age;
// this.subject = subject;
// }
// Student.prototype.getDetails = function () {
// console.log( `Name:${this.name},RollNumber:${this.rollNumber},Age:${this.age},Subject:${this.subject}`);
// }
// let st=new Student("Anant",789,90,"Maths");
// st.getDetails();
// After ES6
class Student{
constructor(name, rollNumber, age, subject) {
this.name = name;
this.rollNumber = rollNumber;
this.age = age;
this.subject = subject;
}
getDetails(){
console.log( `Name:${this.name},RollNumber:${this.rollNumber},Age:${this.age},Subject:${this.subject}`);
}
}
let student1=new Student("Anant",789,90,"Maths");
student1.getDetails();