summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorPhilippe <pvlerick@gmail.com>2014-08-14 15:56:30 +0200
committerPhilippe <pvlerick@gmail.com>2014-08-14 15:56:30 +0200
commit7d0adf66eab5d391d63c2bcf0fd6b1291d781a22 (patch)
tree2743eb8efdbf40fabcdc67f744c1d028100a6a3f
parent7f2256b2e65cb72ef87a5cff0a63bc4982a5e496 (diff)
Added inheritance and overwrite examples
-rw-r--r--typescript.html.markdown24
1 files changed, 21 insertions, 3 deletions
diff --git a/typescript.html.markdown b/typescript.html.markdown
index 3363426a..3da7bca2 100644
--- a/typescript.html.markdown
+++ b/typescript.html.markdown
@@ -83,8 +83,10 @@ class Point {
//Properties
x: number;
- //Constructor - the public keyword is a shortcut to generate the code for a property and it's initialization, equivalent to "x" in this case
- constructor(x: number, public y: number) {
+ //Constructor - the public/private keywords are shortcuts to generate the code for a property and its initialization
+ //Equivalent to "x" in this case
+ //Default values are also supported
+ constructor(x: number, public y: number = 0) {
this.x = x;
}
@@ -95,7 +97,23 @@ class Point {
static origin = new Point(0, 0);
}
-var p = new Point(10 ,20);
+var p1 = new Point(10 ,20);
+var p2 = new Point(25); //y will be 0
+
+//Inheritance
+class Point3D extends Point {
+ constructor(x: number, y: number, public z: number = 0) {
+ super(x, y); //Explicit call to the super class constructor is mandatory
+ }
+
+ /Overwrite
+ dist() {
+ var d = super.dist();
+ return Math.sqrt(d * d + this.z * this.z);
+ }
+}
+
+//Modules
//Generics