Skip to content

Commit

Permalink
Create slightly more complex example.
Browse files Browse the repository at this point in the history
This example takes the Animal class (defined in sample 1) and
reimplements it in idiomatic TypeScript. Then creates a subclass "Dog"
who can speak.
  • Loading branch information
achew22 committed Apr 28, 2015
1 parent 5865b45 commit 308e309
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
8 changes: 8 additions & 0 deletions examples/walkthrough/classes/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
load("/tools/typescript/typescript", "typescript_binary")

typescript_binary(
name = "classes",
deps = [
"main.ts"
]
)
21 changes: 21 additions & 0 deletions examples/walkthrough/classes/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Sample inheritance in typescript.
class Animal {
constructor(public name: string) { }

sound(sound: string) {
return this.name + " goes " + sound;
};
};

class Dog extends Animal {
constructor(name: string) {
super(name);
}

sound() {
return "My dog " + super.sound("bark!");
}
}

var colby = new Dog("Colby");
alert(colby.sound())

0 comments on commit 308e309

Please sign in to comment.