вторник, 15 декабря 2020 г.

Typescript, Classes

class HelloWorld{
    constructor(
        private hellostring,
        private worldstring
    ){}
    toString = (): string => `Typeof:${typeof this} ${this.hello} ${this.world}`;
}
let hw = new HelloWorld('hello''world');

console.log(hw.toString());

class Point {
    constructor(
        private xnumber
        private ynumber)
        {}    
    getDist = () : number => Math.sqrt(this.x * this.x + this.y * this.y);
    toString = () : string =>
        `Typeof: ${typeof this} x: ${this.x} y: ${this.y} dist: ${this.getDist()}`
}
let point = new Point(3,2);
console.log(point.toString());

Комментариев нет:

Отправить комментарий