| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
class List extends Array { |
| 5 |
constructor(value) { |
| 6 |
super().push(value); |
| 7 |
} |
| 8 |
push(value) { |
| 9 |
super.push(value); |
| 10 |
return this; |
| 11 |
} |
| 12 |
} |
| 13 |
|
| 14 |
expect(new List(1)).toBeInstanceOf(List); |
| 15 |
expect(new List(2)).toBeInstanceOf(Array); |
| 16 |
|
| 17 |
var l = new List(3); |
| 18 |
expect(l).toHaveLength(1); |
| 19 |
expect(l[0]).toBe(3); |
| 20 |
expect(l.push(4)).toBe(l); |
| 21 |
expect(l).toHaveLength(2); |
| 22 |
expect(l.join()).toBe('3,4'); |
| 23 |
|
| 24 |
class SecondLevel extends List { |
| 25 |
method() { |
| 26 |
return this; |
| 27 |
} |
| 28 |
} |
| 29 |
|
| 30 |
expect(new SecondLevel(1)).toBeInstanceOf(SecondLevel); |
| 31 |
expect(new SecondLevel(2)).toBeInstanceOf(List); |
| 32 |
expect(new SecondLevel(3)).toBeInstanceOf(Array); |
| 33 |
|
| 34 |
var s = new SecondLevel(4); |
| 35 |
expect(s).toHaveLength(1); |
| 36 |
expect(s[0]).toBe(4); |
| 37 |
expect(s.push(5)).toBe(s); |
| 38 |
expect(s).toHaveLength(2); |
| 39 |
expect(s.join()).toBe('4,5'); |
| 40 |
expect(s.method()).toBe(s); |