-
Notifications
You must be signed in to change notification settings - Fork 0
/
inheritance.js
61 lines (49 loc) · 1.01 KB
/
inheritance.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
describe('inheritance', function(){
it('inheritance and extension', function(){
class Animal {
constructor(name) {
this._name = name;
}
get name() {
return this._name;
}
set name(value) {
this._name = value;
}
}
class Cat extends Animal {
greeting() {
return "'Meow' said " + this._name;
}
};
let anymal = new Animal("Anyname");
let mycat = new Cat("Foffi");
expect(anymal.name).toBe("Anyname");
expect(mycat.name).toBe("Foffi");
expect(mycat.greeting()).toBe("'Meow' said Foffi");
});
it('super class', function(){
class Animal {
constructor(name) {
this._name = name;
}
get name() {
return this._name;
}
set name(value) {
this._name = value;
}
}
class Cat extends Animal {
constructor(name, color){
super(name);
this._color = color;
}
get color() {
return this._color;
}
};
let mycat = new Cat("Foffi", "gray");
expect(mycat.color).toBe("gray");
});
});