Skip to content

Instantly share code, notes, and snippets.

@Ibro
Last active March 25, 2017 12:43
Show Gist options
  • Save Ibro/c7f1c736a2419b1ab09b62b874c953bd to your computer and use it in GitHub Desktop.
Save Ibro/c7f1c736a2419b1ab09b62b874c953bd to your computer and use it in GitHub Desktop.
TypeScript decorators composition
class Test {
public name: string;
constructor(name: string) {
this.name = name;
}
@a()
@b()
@c()
public appendTextToName(text: string) {
this.name += text;
return this.name;
}
}
function a() {
console.log('a(): evaluated');
return function (target: any, propertyKey: string, descriptor: PropertyDescriptor) {
console.log('a(): called');
}
}
function b() {
console.log('b(): evaluated');
return function (target: any, propertyKey: string, descriptor: PropertyDescriptor) {
console.log('b(): called');
}
}
function c() {
console.log('c(): evaluated');
return function (target: any, propertyKey: string, descriptor: PropertyDescriptor) {
console.log('c(): called');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment