【发布时间】:2018-05-25 04:00:19
【问题描述】:
我想让getArea() 函数成为原型,但不确定这种 ES6 (?) 格式是否会自动为我执行此操作,或者我是否仍需要在单独的 Object.prototype.method = function() {} 中声明原型
构造?
class Polygon {
constructor(height, width) {
this.height = height;
this.width = width;
}
getArea() {
return this.height * this.width;
}
}
【问题讨论】:
-
您是否有理由不亲自检查?
console.log(Polygon.prototype.getarea)
标签: javascript methods prototype