ts overload constructors

This commit is contained in:
Jörn-Michael Miehe 2023-09-07 03:29:53 +00:00
parent 0dd96f5949
commit dd156b936d
3 changed files with 6 additions and 0 deletions

View file

@ -4,6 +4,8 @@ export class Door {
private _day = -1; private _day = -1;
public position: Rectangle; public position: Rectangle;
constructor(position: Rectangle);
constructor(position: Rectangle, day: number);
constructor(position: Rectangle, day = -1) { constructor(position: Rectangle, day = -1) {
this.day = day; this.day = day;
this.position = position; this.position = position;

View file

@ -4,6 +4,8 @@ export class Rectangle {
private readonly corner_1: Vector2D; private readonly corner_1: Vector2D;
private readonly corner_2: Vector2D; private readonly corner_2: Vector2D;
constructor();
constructor(corner_1: Vector2D, corner_2: Vector2D);
constructor(corner_1 = new Vector2D(), corner_2 = new Vector2D()) { constructor(corner_1 = new Vector2D(), corner_2 = new Vector2D()) {
this.corner_1 = corner_1; this.corner_1 = corner_1;
this.corner_2 = corner_2; this.corner_2 = corner_2;

View file

@ -2,6 +2,8 @@ export class Vector2D {
public readonly x: number; public readonly x: number;
public readonly y: number; public readonly y: number;
constructor();
constructor(x: number, y: number);
constructor(x = 0, y = 0) { constructor(x = 0, y = 0) {
this.x = x; this.x = x;
this.y = y; this.y = y;