本题考点:class、Getter取值函数
核心步骤:
- 创建Rectangle类,在默认方法constructor中写入width,heigh参数(当new Rectangle执行)
- 创建Getter area取值函数,获取area时返回乘积
<script type="text/javascript">
class Rectangle {
constructor(height, width) {
this.height = height
this.width = width
}
get area() {
return this.height * this.width
}
}
</script>

京公网安备 11010502036488号