-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create slightly more complex example.
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
Showing
2 changed files
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) |