Debian Codegraph @

demo/kitchen-sink/docs/typescript.ts

raw
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
11 var greeter = new Greeter("world");
12
13 var button = document.createElement('button')
14 button.innerText = <string>"Say Hello";
15 button.onclick = function() {
16 alert(greeter.greet())
17 }
18
19 document.body.appendChild(button)
20
21 class Snake extends Animal {
22 move() {
23 alert("Slithering...");
24 super(5);
25 }
26 }
27
28 class Horse extends Animal {
29 move() {
30 alert("Galloping...");
31 super.move(45);
32 }
33 }
34
35 module Sayings {
36 export class Greeter {
37 greeting: string;
38 constructor (message: string) {
39 this.greeting = message;
40 }
41 greet() {
42 return "Hello, " + this.greeting;
43 }
44 }
45 }
46 module Mankala {
47 export class Features {
48 public turnContinues = false;
49 public seedStoredCount = 0;
50 public capturedCount = 0;
51 public spaceCaptured = NoSpace;
52
53 public clear() {
54 this.turnContinues = false;
55 this.seedStoredCount = 0;
56 this.capturedCount = 0;
57 this.spaceCaptured = NoSpace;
58 }
59
60 public toString() {
61 var stringBuilder = "";
62 if (this.turnContinues) {
63 stringBuilder += " turn continues,";
64 }
65 stringBuilder += " stores " + this.seedStoredCount;
66 if (this.capturedCount > 0) {
67 stringBuilder += " captures " + this.capturedCount + " from space " + this.spaceCaptured;
68 }
69 return stringBuilder;
70 }
71 }
72 }