扩展

class Point {
    constructor(x, y) {
        this.x = x;
        this.y = y;
    }
}

Point.distanceTo = function distanceTo(p1, p2) {
    let d1 = Math.pow(p1.x - p2.x2);
    let d2 = Math.pow(p1.y - p2.y2);
    return Math.sqrt(d1 + d2);
}

let p1 = new Point(12);
let p2 = new Point(23);
let distance = Point.distanceTo(p1, p2);
//distance is 1.4142

console.log(`distance is ${distance}`);