小编Pav*_*dog的帖子

JavaScript ES6原型功能

我想使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)

javascript methods prototype

2
推荐指数
1
解决办法
304
查看次数

标签 统计

javascript ×1

methods ×1

prototype ×1