diff options
| -rw-r--r-- | typescript.html.markdown | 24 | 
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  | 
