Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 25: class - extends
- // To do: make all tests pass, leave the assert lines unchanged!
- describe('classes can inherit from another', () => {
- describe('the default super class is Object', () => {
- it('class A is an instance of Object', () => {
- class A extends Object{};
- assert.equal(new A() instanceof Object, true);
- });
- //changed let to class and added extends Objects with {}
- it('B extends A, B is also instance of Object', () => {
- class A extends Object{}
- class B extends A{}
- assert.equal(new B() instanceof A, true);
- assert.equal(new B() instanceof Object, true);
- });
- //added "extends Object {}" to class A and added "extends A {}" to class B.
- // because A belongs to Objects, B belongs to A => B belongs/instance to Object
- it('class can extend `null`, not an instance of Object', () => {
- class NullClass extends null{}
- let nullInstance = new NullClass();
- assert.equal(nullInstance instanceof Object, false);
- });
- //changed 'object' to 'null' on line 26 becuase it is not an instance of Object
- });
- describe('instance of', () => {
- it('when B inherits from A, `new B()` is also an instance of A', () => {
- class A{};
- class B extends A {}
- assert.equal(new B() instanceof A, true);
- });
- //changed let to class and added {} because let is a variable (like var) and class defined a blueprint
- it('extend over multiple levels', () => {
- class A {}
- class B extends A {} //added this line to define B belongs to A so C can belongs to B => C belongs to A
- class C extends B {}
- let instance = new C();
- // changed 'let instance = C;' by adding 'new' word in front of C with ()
- //"new C ()" or "new B ()" defines a real product of the class, while class is just a blueprint (like a construction plan)
- assert.equal(instance instanceof A, true);
- });
- });
- });
Add Comment
Please, Sign In to add comment