Importance of Decorators
So, now you're ready to start decorating. But why would you want to do that? Let's run through a simple example that mimics the real-world scenarios you will be encountering later. Let's say that you are building a simple class that will encapsulate the score for a basketball game:
Example_Basketball.ts
1 interface Team { 2 score: number; 3 name: string; 4 } 5 6 class BasketBallGame { 7 private team1: Team; 8 private team2: Team; 9 10 constructor(teamName1: string, teamName2: string) { 11 this.team1 = { score: 0, name: teamName1 }; 12 this.team2 = { score: 0, name: teamName2 }; 13 } 14 15 getScore() { 16 return `${this.team1.score}:${this.team2.score}`; 17 } 18 } 19 20 const game = new BasketBallGame("LA Lakers", "Boston Celtics");
Link to the preceding example: https://packt.link/ORdNl.
Our class has two teams, each of which has a name and a...