<commit_before><commit_msg>Some super in constructor challenges.<commit_after>// 28: class - super in constructor
// To do: make all tests pass, leave the assert lines unchanged!

describe('class', () => {

  it('use `super()` to call the parent constructor', () => {
    class A {constructor() { this.levels = 1; }}
    class B extends A {
      constructor() { 
        super();
        this.levels++; 
      }
    }
    
    assert.equal(new B().levels, 2);
  });

  it('`super()` may also take params', () => {
    class A {constructor(startValue=1, addTo=1) { this.counter = startValue + addTo; }}
    class B extends A {
      constructor(...args) { 
        super(...args);
        this.counter++; 
      }
    }
    
    assert.equal(new B(42, 2).counter, 45);
  });
  
  it('it is important where you place your `super()` call!', () => {
    class A {constructor() { this.countUp = 1; }}
    class B extends A {
      constructor() { 
        this.countUp = 2; 
        super();
      }
    }
    
    assert.equal(new B().countUp, 1);
  });

  it('you can dynamically check for a parent constructor', () => {
    class A extends null {
      constructor() {
        this.isTop = false;
        try {
          this.isTop = !!super.constructor;
        } catch (e) {}
      }
    }

    assert.equal(new A().isTop, false);
  });
  
});

{'fraction_non_alphanumeric': 0.1620817843866171, 'fraction_numerical': 0.010408921933085501, 'mean_word_length': 2.080091533180778, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4901123', 'n_tokens_mistral': 438, 'n_tokens_neox': 407, 'n_words': 115}