-
Notifications
You must be signed in to change notification settings - Fork 20
/
26-class-more-extends.js
43 lines (34 loc) · 1.23 KB
/
26-class-more-extends.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
// 26: class - more-extends
// To do: make all tests pass, leave the assert lines unchanged!
describe('class can inherit from another', () => {
it('extend an `old style` "class", a function, still works', () => {
let A = function(){};
class B extends A {}
assert.equal(new B() instanceof A, true);
});
describe('prototypes are as you know them', () => {
class A {}
class B extends A {}
it('A is the prototype of B', () => {
const isIt = A.isPrototypeOf(B);
assert.equal(isIt, true);
});
it('A`s prototype is also B`s prototype', () => {
const proto = B.prototype;
// Remember: don't touch the assert!!! :)
assert.equal(A.prototype.isPrototypeOf(proto), true);
});
});
describe('`extends` using an expression', () => {
it('eg the inline assignment of the parent class', () => {
let A;
class B extends (A = class {}) {}
assert.equal(new B() instanceof A, true);
});
it('or calling a function that returns the parent class', () => {
const returnParent = (beNull) => beNull ? null : class {};
class B extends (returnParent(true)) {}
assert.equal(Object.getPrototypeOf(B.prototype), null);
});
});
});