mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2025-04-27 07:33:57 +00:00
fix spacing issue
This commit is contained in:
parent
394e7ecb84
commit
69480d51b8
@ -43,14 +43,14 @@ function bigHorribleAlert(): void {
|
|||||||
|
|
||||||
// The following are equivalent, the same signature will be infered by the
|
// The following are equivalent, the same signature will be infered by the
|
||||||
// compiler, and same JavaScript will be emitted
|
// compiler, and same JavaScript will be emitted
|
||||||
var f1 = function(i: number) : number { return i * i; }
|
var f1 = function(i: number): number { return i * i; }
|
||||||
// Return type inferred
|
// Return type inferred
|
||||||
var f2 = function(i: number) { return i * i; }
|
var f2 = function(i: number) { return i * i; }
|
||||||
var f3 = (i: number) : number => { return i * i; }
|
var f3 = (i: number): number => { return i * i; }
|
||||||
// Return type inferred
|
// Return type inferred
|
||||||
var f4 = (i: number) => { return i * i; }
|
var f4 = (i: number) => { return i * i; }
|
||||||
// Return type inferred, one-liner means no return keyword needed
|
// Return type inferred, one-liner means no return keyword needed
|
||||||
var f5 = (i: number) => i * i;
|
var f5 = (i: number) => i * i;
|
||||||
|
|
||||||
// Interfaces are structural, anything that has the properties is compliant with
|
// Interfaces are structural, anything that has the properties is compliant with
|
||||||
// the interface
|
// the interface
|
||||||
@ -64,11 +64,11 @@ interface Person {
|
|||||||
|
|
||||||
// Object that implements the "Person" interface
|
// Object that implements the "Person" interface
|
||||||
// Can be treated as a Person since it has the name and move properties
|
// Can be treated as a Person since it has the name and move properties
|
||||||
var p : Person = { name: "Bobby", move : () => {} };
|
var p: Person = { name: "Bobby", move: () => {} };
|
||||||
// Objects that have the optional property:
|
// Objects that have the optional property:
|
||||||
var validPerson : Person = { name: "Bobby", age: 42, move: () => {} };
|
var validPerson: Person = { name: "Bobby", age: 42, move: () => {} };
|
||||||
// Is not a person because age is not a number
|
// Is not a person because age is not a number
|
||||||
var invalidPerson : Person = { name: "Bobby", age: true };
|
var invalidPerson: Person = { name: "Bobby", age: true };
|
||||||
|
|
||||||
// Interfaces can also describe a function type
|
// Interfaces can also describe a function type
|
||||||
interface SearchFunc {
|
interface SearchFunc {
|
||||||
@ -84,7 +84,7 @@ mySearch = function(src: string, sub: string) {
|
|||||||
class Point {
|
class Point {
|
||||||
// Properties
|
// Properties
|
||||||
x: number;
|
x: number;
|
||||||
|
|
||||||
// Constructor - the public/private keywords in this context will generate
|
// Constructor - the public/private keywords in this context will generate
|
||||||
// the boiler plate code for the property and the initialization in the
|
// the boiler plate code for the property and the initialization in the
|
||||||
// constructor.
|
// constructor.
|
||||||
@ -94,10 +94,10 @@ class Point {
|
|||||||
constructor(x: number, public y: number = 0) {
|
constructor(x: number, public y: number = 0) {
|
||||||
this.x = x;
|
this.x = x;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Functions
|
// Functions
|
||||||
dist() { return Math.sqrt(this.x * this.x + this.y * this.y); }
|
dist() { return Math.sqrt(this.x * this.x + this.y * this.y); }
|
||||||
|
|
||||||
// Static members
|
// Static members
|
||||||
static origin = new Point(0, 0);
|
static origin = new Point(0, 0);
|
||||||
}
|
}
|
||||||
@ -110,7 +110,7 @@ class Point3D extends Point {
|
|||||||
constructor(x: number, y: number, public z: number = 0) {
|
constructor(x: number, y: number, public z: number = 0) {
|
||||||
super(x, y); // Explicit call to the super class constructor is mandatory
|
super(x, y); // Explicit call to the super class constructor is mandatory
|
||||||
}
|
}
|
||||||
|
|
||||||
// Overwrite
|
// Overwrite
|
||||||
dist() {
|
dist() {
|
||||||
var d = super.dist();
|
var d = super.dist();
|
||||||
|
Loading…
Reference in New Issue
Block a user