扩展

class Size {
    constructor(width, height) {
        this.width = width;
        this.height = height;
    }
}

Object.defineProperty(Size.prototype"area", {
        getfunction area() {
            return this.width * this.height;
        }
});

let size = new Size(45);
let area = size.area;
//area is 20

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