Skip to content

Latest commit

 

History

History
23 lines (17 loc) · 721 Bytes

parameter_decorators.md

File metadata and controls

23 lines (17 loc) · 721 Bytes

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 with Angular 2 can now imagine how Angular 2 implemented their @Inject() system.