• @Konkery, did you even try? where is your 'correct' code and the console output? ...because it just works...

    Here the fixed code (w/ B extending A) with the two presented options for tackling the correct context:

    // someES6Test01.js
    //
    class A {
        constructor(x, y) { // class field...
          this.x = x;
          this.y = y;
        }
        asyncFuncA() { // code...
            console.log("A.asyncFuncA()");
        }
        run() { // call async code
            var _this = this;
            setInterval(() => {
                _this.asyncFuncA();
            }, 1000);
        }
    }
    class B extends A {
        constructor(x, y){
            super(x,y);
        }
        AsyncFuncB() { //code...
            console.log("B.asyncFuncB()");
        }
        run() { // call async code
            super.run();
            setInterval((_) => { // Todo...
                _.AsyncFuncB();
            }, 2000, this);
        }
    }
    /**********************************************/
    let x = 1; let y = 2;
    let ob = new B(x, y);
    
    function onInit() {
      ob.run();
    }
    
    setTimeout(onInit,500); // while dev'n```
    

    And related console output (PICO w/ Espruino 2v01):

    >
     ____                 _
    |  __|___ ___ ___ _ _|_|___ ___
    |  __|_ -| . |  _| | | |   | . |
    |____|___|  _|_| |___|_|_|_|___|
             |_| espruino.com
     2v01 (c) 2018 G.Williams
    >
    A.asyncFuncA()
    A.asyncFuncA()
    B.asyncFuncB()
    A.asyncFuncA()
    A.asyncFuncA()
    B.asyncFuncB()
    A.asyncFuncA()
    A.asyncFuncA()
    B.asyncFuncB()
    A.asyncFuncA()
    >reset() // entered to stop running intervals
    =undefined
    > 
    

    Since there were other bugs in the code - missing parent class reference extends B- , I'm suspicious about even needing the work around - with correct code... I try now the code with out the tackling of the this context, but with fixed class B... (and some more identifiable output in the console):

    AND IT WORKS TOO - I assume now that you ran a different code than what you pug in post #1,... and that code is buggy on some other terms...

    // someES6Test01b.js
    //
    class A {
        constructor(x, y) { // class field...
          this.x = x;
          this.y = y;
        }
        asyncFuncA() { // code...
            console.log("A.asyncFuncA()",getTime() % 100);
        }
        run() {
            //call async code
            setInterval(() => {
                this.asyncFuncA();
            }, 1000);
        }
    }
    class B extends A {
        constructor(x, y) {
            super(x,y);
        }
        asyncFuncB() { // code...
            console.log("B.asyncFuncB()",getTime() % 100);
        }
        run() { // call async code
            super.run();
            setInterval(() => { // Todo...
                this.asyncFuncB();
            }, 2000);
        }
    }
    /**********************************************/
    let x = 1; let y = 2;
    let ob = new B(x, y);
    
    function onInit() {
      ob.run();
    }
    
    setTimeout(onInit,500); // while dev'n
    

    ...and related output:

    >
     ____                 _
    |  __|___ ___ ___ _ _|_|___ ___
    |  __|_ -| . |  _| | | |   | . |
    |____|___|  _|_| |___|_|_|_|___|
             |_| espruino.com
     2v01 (c) 2018 G.Williams
    >
    A.asyncFuncA() 64.51624393463
    A.asyncFuncA() 65.51623725891
    B.asyncFuncB() 65.51758861541
    A.asyncFuncA() 66.51625156402
    A.asyncFuncA() 67.51624679565
    B.asyncFuncB() 67.51758384704
    A.asyncFuncA() 68.51623630523
    A.asyncFuncA() 69.51630210876
    B.asyncFuncB() 69.51768684387
    A.asyncFuncA() 70.51631069183
    A.asyncFuncA() 71.51631927490
    B.asyncFuncB() 71.51773548126
    A.asyncFuncA() 72.51630496978
    A.asyncFuncA() 73.51627349853
    B.asyncFuncB() 73.51770114898
    >reset() // entered to stop running intervals
    =undefined
    

    Conclusion: Everything is just fine... @Gordon: 100 pts, @candidate: 0 - GAME OVER

  • Sat 2019.03.02

    I wish I had as much time as you do @allObjects to try all these situations. ;-)
    I'm not worthy. (ref Wayne's World)

    Good catch Line #18
    class B extends A


    That and; It is most likely 1v96 that is causing the headache as I pointed out in #11 and that @opichals may not have tested using 2v01 as did you.
    (ref mods to extends-super and constructor scope that occurred 2v00-2v01)

    Law of unintended consequences not keeping up on current releases. . . .

  • Console conclusion at implementation of your code:

        ____       __
       /  _/_____ / /__ _____ ____ _
       / / / ___// //_// ___// __ `/
     _/ / (__  )/ ,<  / /   / /_/ /
    /___//____//_/|_|/_/    \__,_/
    Based on Espruino 1v96.43
    (c) 2018 G.Williams, Amperka LLC
    Support the work of core developers:
    http://espruino.com/Donate
    >
    =undefined
    Uncaught Error: Function "asyncFuncA" not found!
     at line 1 col 7
    _this.asyncFuncA();
          ^
    in function called from system
    
About

Avatar for allObjects @allObjects started