core-decorators icon indicating copy to clipboard operation
core-decorators copied to clipboard

@autobind doesn't work properly when calling super from the parent's parent's parent.

Open JabX opened this issue 9 years ago • 4 comments

Hello it's me again, from #69 Your fix worked for a super call on the parent's parent, but when I try to go even further up the chain I'm it still doesn't bind properly. I'm sorry to bother you with such edge cases, but you'd be my hero if you could find a solution. Thanks.

JabX avatar May 10 '16 13:05 JabX

Heard you like super from parent's parent's parent

image

jayphelps avatar May 11 '16 03:05 jayphelps

Can you provide some actual code I can use to reproduce? 💃

Also--this is in TypeScript again right?

jayphelps avatar May 11 '16 03:05 jayphelps

Yup, still in Typescript.

Code would be like

@autobind
class A {
    method() {
          console.log(this.test);
    }
}

@autobind
class B extends A {
}

@autobind
class C extends B {
}

@autobind
class D extends C {
    test = 'hello';

    method() {
           super.method();
     }
}

JabX avatar May 11 '16 06:05 JabX

I encoutered the issue again yesterday and it made me think that if the problem is really related to the way Typescript transpile classes down to ES5, you should be able to reproduce that with Babel with the "loose-class-transform" option. It essentially ditches the strictness of the default transpilation to something lighter that performs better and works on older browsers (I think it the default only works on IE 11), which is very similar to what Typescript does.

JabX avatar Jul 21 '16 15:07 JabX