Skip to content

Instantly share code, notes, and snippets.

@jeffwhelpley
Last active February 14, 2017 02:40
Show Gist options
  • Save jeffwhelpley/8f862be52d555a8312de3b99184d1a05 to your computer and use it in GitHub Desktop.
Save jeffwhelpley/8f862be52d555a8312de3b99184d1a05 to your computer and use it in GitHub Desktop.
Examples of different types of decorators
export function ClassDecorator(meta?: any): Function {
return function (target: any) {
let targetProto = target.prototype;
let targetMeta = targetProto.__meta = targetProto.__meta || {};
targetMeta.cls = meta;
};
}
export function MethodDecorator(meta?: any): Function {
return function (targetProto: any, methodName: string) {
let targetMeta = targetProto.__meta = targetProto.__meta || {};
targetMeta.methods = targetMeta.methods || {};
targetMeta.methods[methodName] = meta;
};
}
export function PropertyDecorator(meta?: any): Function {
return function (targetProto: any, propertyName: string) {
let targetMeta = targetProto.__meta = targetProto.__meta || {};
targetMeta.properties = targetMeta.properties || {};
targetMeta.properties[propertyName] = meta;
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment