mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2025-08-10 16:54:33 +02:00
Merge branch 'master' of github.com:adambard/learnxinyminutes-docs
This commit is contained in:
@@ -4,6 +4,7 @@ contributors:
|
|||||||
- ["Chaitanya Krishna Ande", "http://icymist.github.io"]
|
- ["Chaitanya Krishna Ande", "http://icymist.github.io"]
|
||||||
- ["Colton Kohnke", "http://github.com/voltnor"]
|
- ["Colton Kohnke", "http://github.com/voltnor"]
|
||||||
- ["Sricharan Chiruvolu", "http://sricharan.xyz"]
|
- ["Sricharan Chiruvolu", "http://sricharan.xyz"]
|
||||||
|
- ["Ramanan Balakrishnan", "https://github.com/ramananbalakrishnan"]
|
||||||
filename: learn-latex.tex
|
filename: learn-latex.tex
|
||||||
---
|
---
|
||||||
|
|
||||||
|
@@ -46,7 +46,7 @@ let `class` = "keyword" // backticks allow keywords to be used as variable names
|
|||||||
let explicitDouble: Double = 70
|
let explicitDouble: Double = 70
|
||||||
let intValue = 0007 // 7
|
let intValue = 0007 // 7
|
||||||
let largeIntValue = 77_000 // 77000
|
let largeIntValue = 77_000 // 77000
|
||||||
let label = "some text " + String(myVariable) // Casting
|
let label = "some text " + String(myVariable) // String construction
|
||||||
let piText = "Pi = \(π), Pi 2 = \(π * 2)" // String interpolation
|
let piText = "Pi = \(π), Pi 2 = \(π * 2)" // String interpolation
|
||||||
|
|
||||||
// Build Specific values
|
// Build Specific values
|
||||||
|
@@ -83,23 +83,23 @@ mySearch = function(src: string, sub: string) {
|
|||||||
// Classes - members are public by default
|
// Classes - members are public by default
|
||||||
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.
|
||||||
// In this example, "y" will be defined just like "x" is, but with less code
|
// In this example, "y" will be defined just like "x" is, but with less code
|
||||||
// Default values are also supported
|
// Default values are also supported
|
||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
var p1 = new Point(10 ,20);
|
var p1 = new Point(10 ,20);
|
||||||
@@ -107,15 +107,15 @@ var p2 = new Point(25); //y will be 0
|
|||||||
|
|
||||||
// Inheritance
|
// Inheritance
|
||||||
class Point3D extends Point {
|
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();
|
||||||
return Math.sqrt(d * d + this.z * this.z);
|
return Math.sqrt(d * d + this.z * this.z);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Modules, "." can be used as separator for sub modules
|
// Modules, "." can be used as separator for sub modules
|
||||||
@@ -139,19 +139,19 @@ var s2 = new G.Square(10);
|
|||||||
// Generics
|
// Generics
|
||||||
// Classes
|
// Classes
|
||||||
class Tuple<T1, T2> {
|
class Tuple<T1, T2> {
|
||||||
constructor(public item1: T1, public item2: T2) {
|
constructor(public item1: T1, public item2: T2) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Interfaces
|
// Interfaces
|
||||||
interface Pair<T> {
|
interface Pair<T> {
|
||||||
item1: T;
|
item1: T;
|
||||||
item2: T;
|
item2: T;
|
||||||
}
|
}
|
||||||
|
|
||||||
// And functions
|
// And functions
|
||||||
var pairToTuple = function<T>(p: Pair<T>) {
|
var pairToTuple = function<T>(p: Pair<T>) {
|
||||||
return new Tuple(p.item1, p.item2);
|
return new Tuple(p.item1, p.item2);
|
||||||
};
|
};
|
||||||
|
|
||||||
var tuple = pairToTuple({ item1:"hello", item2:"world"});
|
var tuple = pairToTuple({ item1:"hello", item2:"world"});
|
||||||
|
Reference in New Issue
Block a user