我想使getArea()函数成为原型,并且不确定此ES6(?)格式是否为我自动完成此操作,还是仍需要在单独的Object.prototype.method = function() {}
构造中声明原型?
class Polygon {
constructor(height, width) {
this.height = height;
this.width = width;
}
getArea() {
return this.height * this.width;
}
}
Run Code Online (Sandbox Code Playgroud)