-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode_10122022.js
More file actions
82 lines (55 loc) · 1.76 KB
/
Copy pathcode_10122022.js
File metadata and controls
82 lines (55 loc) · 1.76 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// ES6 class method
class Person{
constructor(first,last,age,gender,interests){
this.name={
first,
last
};
this.age=age;
this.gender=gender;
this.interests=interests;
}
greeting(){
console.log(`Hi!I'm${this.name.first}`);
};
farewell(){
console.log(`${this.name.first}has left the building. Bye for now!`)
};
}
let han =new Person('Han','Solo',25,'male',['Smuggling']);
han.greeting();
let leia =new Person('Han','Solo',25,'male',['Smuggling']);
leia.farewell();
// in ES6, class is just Syntactic sugar
// class Teacher extends Person {
// constructor(first,last,age,gender,interests,subject,grade){
// super(first,last,age,gender,interests); // Now 'this' is initialized by calling the parent constructor
// this.subject=subject;
// this.grade=grade;
// }
// }
// let snape= new Teacher('Severus','Snape',58,'male',['Potions'],'Dark arts',5);
// snape.greeting();
// snape.farewell();
// snape.age;
// snape.subject;
class Teacher extends Person {
constructor(first, last,age, gender,interests,subjects,grade){
super(first,last,age,gender,interests);
this._subjects=subjects;
this.grade=grade;
}
get subject(){
return this._subject;
}
set subject(newSubject){
this._subject=newSubject;
}
}
let snape= new Teacher('Severus','Snape',58,'male',['Potions'],'Dark arts',5);
//check the default value
console.log(snape.subject)
snape.subject="Balloon animas" // Sets _subject to "Balloon animals"
console.log(snape.subject)
// in ES6, because i have java experience, we see the class and extends
// and also the super(), getter, setter method which are used in java bean object.