Created
September 2, 2017 15:58
-
-
Save JaykeOps/650e6e9ccb2898dc9f521d6e34d76f31 to your computer and use it in GitHub Desktop.
Just some notes I took while following allong the TypeScript documentation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//1.0 TypeScript Inheritance | |
class Diety { | |
constructor(protected name: string) { | |
} | |
} | |
interface IDietyAction { | |
(name: string): void | |
}; | |
class Zeus extends Diety { | |
public constructor(name: string, private readonly dietyAction: IDietyAction) { | |
super(name); | |
} | |
public throwBolt() { | |
this.dietyAction(this.name); | |
} | |
} | |
let zeusAction = function (name: string) { | |
console.log(name + ": throws a bolt!"); | |
} | |
let zeus = new Zeus("Zeus", zeusAction); | |
zeus.throwBolt(); | |
//1.1 TypeScript Getter | |
class Thor extends Diety { | |
private readonly action; | |
public constructor(name: string, private readonly dietyAction: IDietyAction) { | |
super(name); | |
this.action = dietyAction; | |
} | |
get Name(): string { | |
return this.name; | |
} | |
} | |
let thor = new Thor("Thor", function (name: string) { | |
console.log(name + ": strikes sparks using Mjölner!"); | |
}) | |
console.log(thor.Name); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment