Guest User

Untitled

a guest
Apr 25th, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. // 26: class - more-extends
  2. // To do: make all tests pass, leave the assert lines unchanged!
  3.  
  4. describe('class can inherit from another', () => {
  5.  
  6. it('extend an `old style` "class", a function, still works', () => {
  7. class A{};
  8. class B extends A {}
  9.  
  10. assert.equal(new B() instanceof A, true);
  11. });
  12.  
  13. describe('prototypes are as you know them', () => {
  14. class A {}
  15. class B extends A {}
  16. it('A is the prototype of B', () => {
  17. const isIt = A.isPrototypeOf(B);
  18. assert.equal(isIt, true);
  19. });
  20. it('A`s prototype is also B`s prototype', () => {
  21. const proto = new B;
  22. // Remember: don't touch the assert!!! :)
  23. assert.equal(A.prototype.isPrototypeOf(proto), true);
  24. });
  25. });
  26.  
  27. describe('`extends` using an expression', () => {
  28. it('eg the inline assignment of the parent class', () => {
  29. class A{};
  30. class B extends A{}
  31.  
  32. assert.equal(new B() instanceof A, true);
  33. });
  34.  
  35. it('or calling a function that returns the parent class', () => {
  36. const returnParent = (beNull) => beNull ? null : class {};
  37. class B extends (returnParent(true)) {}
  38.  
  39. assert.equal(Object.getPrototypeOf(B.prototype), null);
  40. });
  41. });
  42.  
  43. });
Add Comment
Please, Sign In to add comment