Skip to content

@bind decorator bug when super method is called #12

Open

Description

@precious

This snippet demonstrates that the bind decorator does not work correctly on second method call if that method invokes super method which in turn is also decorated:

class A {
    @bind
    f() {
        console.log('I\'m A.f');
    }
}

class B extends A {
    @bind
    f() {
        console.log('I\'m B.f BEGIN');
        super.f();
        console.log('I\'m B.f END');
    }
}

let b = new B();
console.log('call b.f() 1st time:');
b.f();
console.log('call b.f() 2nd time:');
b.f();

Output:

call b.f() 1st time:
I'm B.f BEGIN
I'm A.f
I'm B.f END
call b.f() 2nd time:
I'm A.f

Activity

  1. precious commented on Sep 2, 2017

    @precious
    Author

    This bug can be reproduced with babel es2015 preset.
    With .babelrc config

    {"presets": ["es2015"], "plugins": ["transform-decorators-legacy"]}

    and mocha option --compilers js:babel-core/register.

  2. developit commented on Sep 2, 2017

    @developit
    Owner

    Hmm interesting. I've never used this with prototypal inheritance, I can see how it'd overwrite itself like that. Not sure what the best solution for this would be, seems like any fix would break the lazy-binding behavior, which is sortof the big selling feature of this method.

  3. added a commit that references this issue on Sep 3, 2017
    8c45b58
  4. precious commented on Sep 3, 2017

    @precious
    Author

    This fix may help. It prevents defineProperty for this if property is accessed from a super class.
    Let me know if this solution is acceptable -- I'll create a pull request.

  5. wy193777 commented on Apr 13, 2018

    @wy193777

    @memoize also not working when super class' method is called.

  6. Finesse commented on Feb 4, 2019

    @Finesse

    How does the example even work? When I run it, I get an error:

    Cannot set property f of #<B> which has only a getter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions