autobind decorator
class A {
constructor() {
this.x = 123;
}
@autobind
f() {
return this.x;
}
g() {
return this.x;
}
}
var a = new A();
a.f.call({ x: 456 }) === 123; // true
a.g.call({ x: 456 }) === 456; // true
@autobind
class A {
constructor() {
this.x = 123;
}
f() {
return this.x;
}
g() {
return this.x;
}
}
var a = new A();
a.f.call({ x: 456 }) === 123; // true
a.g.call({ x: 456 }) === 123; // true