- Expert Angular
- Mathieu Nayrolles Rajesh Gunasundaram Sridhar Rao
- 188字
- 2021-07-15 17:05:35
Parameter decorators
Parameter decorators are prefixed to parameter declarations, and they are applied to a function for a class constructor or a method declaration. The signature of ParameterDecorator is as follows:
declare type ParameterDecorator = (target: Object, propertyKey: string | symbol, parameterIndex: number) => void;
Now, let's define the Customer class and use a parameter decorator to decorate a parameter in order to make it required and validate whether the value has been served:
class Customer { constructor() { } getName(@logging name: string) { return name; } }
Here, the name parameter has been decorated with @logging. The parameter decorator implicitly takes three inputs, namely prototype of the class that has this decorator, the name of the method that has this decorator, and the index of the parameter that is being decorated. The logging function implementation of the parameter decorator is as follows:
function logging(target: any, key : string, index : number) { console.log(target); console.log(key); console.log(index); }
Here, target is the class that has the decorator, key is the function name, and index contains the parameter index. This code just logs target, key, and index to the console.
- AngularJS Testing Cookbook
- 觸·心:DT時代的大數據精準營銷
- CMDB分步構建指南
- Pandas Cookbook
- 簡單高效LATEX
- Ext JS Data-driven Application Design
- JavaScript Unlocked
- Learning Elixir
- Building Mobile Applications Using Kendo UI Mobile and ASP.NET Web API
- CKA/CKAD應試教程:從Docker到Kubernetes完全攻略
- 琢石成器:Windows環境下32位匯編語言程序設計
- Access 2010中文版項目教程
- Java并發編程之美
- Mastering Elixir
- CodeIgniter Web Application Blueprints