Guest User

Untitled

a guest
Jul 19th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. // 25: class - extends
  2. // To do: make all tests pass, leave the assert lines unchanged!
  3.  
  4. describe('classes can inherit from another', () => {
  5.  
  6. describe('the default super class is Object', () => {
  7.  
  8. it('class A is an instance of Object', () => {
  9. class A extends Object{};
  10.  
  11. assert.equal(new A() instanceof Object, true);
  12. });
  13. //changed let to class and added extends Objects with {}
  14. it('B extends A, B is also instance of Object', () => {
  15. class A extends Object{}
  16. class B extends A{}
  17.  
  18. assert.equal(new B() instanceof A, true);
  19. assert.equal(new B() instanceof Object, true);
  20. });
  21.  
  22. //added "extends Object {}" to class A and added "extends A {}" to class B.
  23. // because A belongs to Objects, B belongs to A => B belongs/instance to Object
  24.  
  25. it('class can extend `null`, not an instance of Object', () => {
  26. class NullClass extends null{}
  27.  
  28. let nullInstance = new NullClass();
  29. assert.equal(nullInstance instanceof Object, false);
  30. });
  31. //changed 'object' to 'null' on line 26 becuase it is not an instance of Object
  32. });
  33.  
  34. describe('instance of', () => {
  35. it('when B inherits from A, `new B()` is also an instance of A', () => {
  36. class A{};
  37. class B extends A {}
  38.  
  39. assert.equal(new B() instanceof A, true);
  40. });
  41. //changed let to class and added {} because let is a variable (like var) and class defined a blueprint
  42. it('extend over multiple levels', () => {
  43. class A {}
  44. class B extends A {} //added this line to define B belongs to A so C can belongs to B => C belongs to A
  45. class C extends B {}
  46.  
  47. let instance = new C();
  48. // changed 'let instance = C;' by adding 'new' word in front of C with ()
  49. //"new C ()" or "new B ()" defines a real product of the class, while class is just a blueprint (like a construction plan)
  50. assert.equal(instance instanceof A, true);
  51. });
  52. });
  53. });
Add Comment
Please, Sign In to add comment