February 2019
Beginner
694 pages
18h 4m
English
Property decorators are decorator functions that can be used on class properties. A property decorator is called with two parameters—the class prototype itself, and the property name. As an example of this, consider the following code:
function propertyDec(target: any, propertyKey : string) {
console.log(`target : ${target}`);
console.log(`target.constructor : ${target.constructor}`);
console.log(`class name : `
+ `${target.constructor.name}`);
console.log(`propertyKey : ${propertyKey}`);
}
class ClassWithPropertyDec {
@propertyDec
name: string;
}
Here, we have defined a property decorator named propertyDec that accepts two parameters—target and propertyKey. The target parameter is of type any, and the propertyKey parameter ...
Read now
Unlock full access