- 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.
- Visual C++程序設(shè)計(jì)教程
- 國(guó)際大學(xué)生程序設(shè)計(jì)競(jìng)賽中山大學(xué)內(nèi)部選拔真題解(二)
- HBase從入門到實(shí)戰(zhàn)
- 你不知道的JavaScript(中卷)
- Android傳感器開發(fā)與智能設(shè)備案例實(shí)戰(zhàn)
- Swift High Performance
- Less Web Development Cookbook
- Spring Web Services 2 Cookbook
- PyTorch生成對(duì)抗網(wǎng)絡(luò)編程
- HTML5+CSS3+JavaScript案例實(shí)戰(zhàn)
- Test-Driven Java Development(Second Edition)
- Go Programming Blueprints
- C#面向?qū)ο蟪绦蛟O(shè)計(jì)(微課版)
- Magento 2 Development Essentials
- 微信小程序開發(fā)零基礎(chǔ)入門