Typescript. Static methods and fields
Here is the same idea as in C#, Java and other langs. Static methods are methods that more devoted to class rather than to instance
Here is the same idea as in C#, Java and other langs. Static methods are methods that more devoted to class rather than to instance
works only with ecmaScript2015
class Man { private _name: string = «DefaultName»; get name(): string { return this._name } set name(value: string) { console.log(‘been here’);
public // by default
private // only inside class
protected // only inside class and its inheritors
readonly // readonly
a little bit of
ABSTRACT CLASSES EXAMPLE abstract class Prayer { abstract pray: string; abstract makeSins(): void; doPray(): string { return this.pray; } } class Muslim extends Prayer {
enum Sex { Man, Woman } class Man { name: string = «DefaultName»; family: string = «DefaultFamily»; age: number = 18; readonly sex: Sex.Man constructor(name:
enum Sex { Man, Woman } class Man { name: string = «DefaultName»; family: string = «DefaultFamily»; age: number = 18; readonly sex: Sex.Man constructor(name:
with defining data types (e.g. annotations) function add(a: number, b: number): number { return a + b; } without annotations function add2(a, b) { return
// — BOOLEAN let b: boolean = true; console.log(‘boolean ‘ + b + ‘ typeof ‘ + typeof b); // — STRING let s: string
noEmitOnError
lets write this piece of code
index.ts
let x = 0; console.log(x); var x = 1; console.log(x);
on compling with tsc index.ts