Parameter Decorators
function logPosition(target: any, propertyKey: string, parameterIndex: number) {
console.log(parameterIndex);
}
class Cow {
say(b: string, @logPosition c: boolean) {
console.log(b);
}
}
new Cow().say('hello', false); // outputs 1 (newline) hello
The above demonstrates decorating method parameters. Readers familiar withAngular can now imagine how Angular implemented their@Inject()
system.
原文: https://angular-2-training-book.rangle.io/handout/features/parameter_decorators.html