comparison Deprecated/Resources/CodeGeneration/Graveyard/playground2.ts @ 1401:f6a2d46d2b76

moved CodeGeneration into Deprecated
author Alain Mazy <alain@mazy.be>
date Wed, 29 Apr 2020 20:48:18 +0200
parents Resources/CodeGeneration/Graveyard/playground2.ts@6405435480ae
children
comparison
equal deleted inserted replaced
1400:419d0320c344 1401:f6a2d46d2b76
1 class Greeter {
2 greeting: string;
3 constructor(message: string) {
4 this.greeting = message;
5 }
6 greet() {
7 return "Hello, " + this.greeting;
8 }
9 }
10 enum Color {
11 Red,
12 Green,
13 Blue,
14 };
15
16 function ColorToString(value: Color)
17 {
18 switch (value)
19 {
20 case Color.Red:
21 return "Red";
22 case Color.Green:
23 return "Green";
24 case Color.Blue:
25 return "Blue";
26 default:
27 throw new Error(`Unrecognized Color value(${value})`);
28 }
29 }
30
31 let color: Color = Color.Red;
32
33 document.body.textContent = "<p>---------------------</p>"
34 document.body.textContent += "<p>********************************</p>"
35
36 class TestMessage {
37 s1: string;
38 s2: Array<string>;
39 s3: Array<Array<string>>;
40 s4: Map<string, number>;
41 s5: Map<number, Array<string>>;
42 s6: Color;
43 s7: boolean;
44 }
45
46 let tm = new TestMessage();
47 tm.s2 = new Array<string>()
48 tm.s2.push("toto");
49 tm.s2.push("toto2");
50 tm.s2.push("toto3");
51 tm.s4 = new Map<string, number>();
52 tm.s4["toto"] = 42;
53 tm.s4["toto"] = 1999;
54 tm.s4["tatata"] = 1999;
55 tm.s6 = Color.Red;
56 tm.s7 = true
57
58 let txt = JSON.stringify(tm)
59 let txtElem = document.createElement('textarea');
60 txtElem.value = txt;
61
62 document.body.appendChild(txtElem);
63
64 let greeter = new Greeter("world");
65
66 let button = document.createElement('button');
67 button.textContent = "Say Hello";
68 button.onclick = function() {
69 alert(greeter.greet());
70 }
71
72 document.body.appendChild(button);