bind-decorator
bind-decorator copied to clipboard
Decorated functions cannot be overwritten
This is what i mean
describe('when used to bind to this context', function () {
class thisContext {
protected test: string;
public constructor() { }
public getTest(): string {
return this.test;
}
@bind
public setTest(test: string): void {
this.test = test;
}
}
it('binds decorated method to this context', function () {
const tested: thisContext = new thisContext();
const { setTest } = tested;
setTest('unit');
expect(tested.getTest()).toBe('unit');
});
it('can be overwritten as well', function () {
class thisInheritedContext extends thisContext {
@bind
public setTest(test: string): void {
this.test = 'inherited ' + test;
}
}
const tested: thisContext = new thisContext();
tested.setTest('unit');
expect(tested.getTest()).toBe('unit');
const inheritedTested: thisInheritedContext = new thisInheritedContext();
inheritedTested.setTest('unit');
expect(inheritedTested.getTest()).toBe('inherited unit');
});
});
Got the same issue
Same here +1
@nostalgiaz @Krakabek @silkimen If still needed https://github.com/NoHomey/bind-decorator/pull/13