class Point {
x: number
y: number
constructor(x: number, y: number) {
this.x = x;
this.y = y;
}
}
interface Point {
distanceTo(p: Point): number
}
Point.prototype.distanceTo = function(p: Point) {
let d1 = Math.pow(this.x - p.x, 2)
let d2 = Math.pow(this.y - p.y, 2)
return Math.sqrt(d1 + d2);
}
let p1 = new Point(1, 2)
let p2 = new Point(2, 3)
let distance = p1.distanceTo(p2)
//distance is 1.4142...
console.log(`distance is ${distance}`)