jayphelps / core-decorators

Library of stage-0 JavaScript decorators (aka ES2016/ES7 decorators but not accurate) inspired by languages that come with built-ins like @​override, @​deprecate, @​autobind, @​mixin and more. Popular with React/Angular, but is framework agnostic.
MIT License
4.51k stars 263 forks source link

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

Open JabX opened 8 years ago

JabX commented 8 years ago

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.

jayphelps commented 8 years ago

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

image

jayphelps commented 8 years ago

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

Also--this is in TypeScript again right?

JabX commented 8 years ago

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 commented 8 years ago

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.