• Example:

    class A {
      constructor() {
      }
    }
    class B extends A {
      constructor() {
        super();
      }
    }
    class C extends B {
      constructor() {
        super();
      }
    }
    new C();
    

    Result:

    Uncaught Error: Too much recursion - the stack is about to overflow
     at line 7 col 1
    super();
    ^
    in function called from line 7 col 7
    super();
          ^
    [.......]
    in function called from line 7 col 7
    super();
          ^
    Execution Interrupted
    
  • @OP, this probably won't help you directly.

    I have done some reading about super lately. Here's a summary:

    • functions created with funcName() syntax (as in class { }) have a hidden attribute pointing to their "HomeObject" - C.prototype and B.prototype in the example here.
      • also true in an object-literal like { foo() { } }, as a pedantic side note
    • super is (should be) Object.prototypeOf(HomeObject)
    • in constructor, super() is shorthand for super.constructor()

    It looks like the call to super at line 7 may be resolving super as Object.prototypeOf(this) instead.

    https://2ality.com/2011/11/super-references.html

    HTH someone

  • Hi - I'm afraid I think you've just hit this bug in Espruino:

    Classes cannot extend classes that extend classes #1529

    https://github.com/espruino/Espruino/issues/1529

    Until it gets fixed there's a workaround mentioned there though

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Calling super() from sub-sub-class leads to infinite loop

Posted by Avatar for coajaxial @coajaxial

Actions