-
Notifications
You must be signed in to change notification settings - Fork 0
/
kata.js
53 lines (43 loc) · 1.19 KB
/
kata.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
// 28: class - super in constructor
// To do: make all tests pass, leave the assert lines unchanged!
describe('class', () => {
it('if you `extend` a class, use `super()` to call the parent constructor', () => {
class A {constructor() { this.levels = 1; }}
class B {
constructor() {
this.levels++;
}
}
assert.equal(new B().levels, 2);
});
it('`super()` may also take params', () => {
class A {constructor(startValue=1, addTo=1) { this.counter = startValue + addTo; }}
class B extends A {
constructor(...args) {
super();
this.counter++;
}
}
assert.equal(new B(42, 2).counter, 45);
});
it('it is important where you place your `super()` call!', () => {
class A {inc() { this.countUp = 1; }}
class B extends A {
inc() {
super.inc();
this.countUp = 2;
return this.countUp;
}
}
assert.equal(new B().inc(), 1);
});
it('use `super.constructor` to find out if there is a parent constructor', () => {
class A extends null {
constructor() {
super();
this.isTop = !!super.constructor;
}
}
assert.equal(new A().isTop, false);
});
});