andreypopp / autobind-decorator

Decorator to automatically bind methods to class instances
MIT License
1.45k stars 66 forks source link

fix(core): allow user set new value #58

Closed acrazing closed 7 years ago

acrazing commented 7 years ago

Allow user to set new value like follow:

class A {
  constructor() {
    this.data = 'A';
  }

  @autobind
  noop() {
    return this.data;
  }
}

const a = new A();
a.noop = function noop () {
  return this.data;
};
const noop = a.noop;
noop();
a.noop = function noop2 () {
  return this.data;
};
const noop2 = a.noop;
noop2();

Please note that the new method bind setter/getter to the field, may cause some performance loss.

stevemao commented 7 years ago

I made 98968ee based on this. Please try it out :)