Skip to content

Instantly share code, notes, and snippets.

@JaykeOps
Created September 2, 2017 15:58
Show Gist options
  • Save JaykeOps/650e6e9ccb2898dc9f521d6e34d76f31 to your computer and use it in GitHub Desktop.
Save JaykeOps/650e6e9ccb2898dc9f521d6e34d76f31 to your computer and use it in GitHub Desktop.
Just some notes I took while following allong the TypeScript documentation
//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