class HelloWorld{
constructor(
private hello: string,
private world: string
){}
toString = (): string => `Typeof:${typeof this} ${this.hello} ${this.world}`;
}
let hw = new HelloWorld('hello', 'world');
console.log(hw.toString());
class Point {
constructor(
private x: number,
private y: number)
{}
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());
Комментариев нет:
Отправить комментарий