Bonjour à tous,
une petite question de débutant : comment peut-on surcharger la méthode toString d'un objet en TypeScript ? J'ai fait ça :
mais ça ne marche pas... Je continu d'avoir [object Object] comme résultat... Si quelqu'un peut éclairer ma lanterne, merci d'avance.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32 export class Location { constructor() { this.postCode = null; } streetNumber: string; multiplier: string; street: string; extension: string; postCode: number; postCodeExtension: string; city: string; public toString(): string { let r: string = ''; r += this.streetNumber; if(this.multiplier != null){ r+=this.multiplier; } r += this.street; if(this.extension != null){ r+=this.extension; } r += this.postCode; if(this.postCodeExtension != null){ r+=this.postCodeExtension; } r += this.city; return r; } }
Partager