Tuesday, May 22, 2018

decorators in TypeScript

This touches on them some. I made the following in playing with a decorator that throws first 13 and then 42 in alerts.

function tusk(constructor: Function) {
   constructor(13);
   alert(this.fatness);
}
 
@tusk
class Walrus{
   fatness: number;
   constructor(_fatness:number) {
      this.fatness = _fatness;
   }
}
 
let walrus = new Walrus(42);
alert(walrus.fatness);

 
 

The walrus example doesn't make any sense, does it?

No comments:

Post a Comment