Skip to content

Commit e06f031

Browse files
committed
bam
1 parent 69dc96d commit e06f031

4 files changed

Lines changed: 69 additions & 0 deletions

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// adapted from an example at http://www.typescriptlang.org/Playground
2+
class Greeter<T> {
3+
greeting: T;
4+
constructor(message: T) {
5+
this.greeting = message;
6+
}
7+
greet() {
8+
return this.greeting;
9+
}
10+
}
11+
12+
var strGreeter = new Greeter<string>("Hello, world");
13+
console.log(strGreeter.greet());
14+
15+
// change x to a number to fix error
16+
var x = 'not a number';
17+
var numGreeter = new Greeter<number>(x);
18+
console.log(numGreeter.greet());

‎v3/ts-example-code/greeter.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// adapted from an example at http://www.typescriptlang.org/Playground
2+
class Greeter {
3+
greeting: string;
4+
constructor(message: string) {
5+
this.greeting = message;
6+
}
7+
greet() {
8+
return "Hello, " + this.greeting;
9+
}
10+
}
11+
12+
13+
var greeter = new Greeter("world");
14+
15+
console.log(greeter.greet());

‎v3/ts-example-code/hello.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
var s: string = 'world';
2+
3+
function yo(x: string) {
4+
console.log('Hello ' + x);
5+
}
6+
7+
yo(s);

‎v3/ts-example-code/inheritance.ts‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Inheritance example from http://www.typescriptlang.org/Playground
2+
class Animal {
3+
constructor(public name: string) { }
4+
move(meters: number) {
5+
console.log(this.name + " moved " + meters + "m.");
6+
}
7+
}
8+
9+
class Snake extends Animal {
10+
constructor(name: string) { super(name); }
11+
move() {
12+
console.log("Slithering...");
13+
super.move(5);
14+
}
15+
}
16+
17+
class Horse extends Animal {
18+
constructor(name: string) { super(name); }
19+
move() {
20+
console.log("Galloping...");
21+
super.move(45);
22+
}
23+
}
24+
25+
var sam = new Snake("Sammy the Python");
26+
var tom: Animal = new Horse("Tommy the Palomino");
27+
28+
sam.move();
29+
tom.move(34);

0 commit comments

Comments
 (0)