题解 | #Getter#
Getter
https://www.nowcoder.com/practice/e7f3a2f429d945e49f5b48ef1065beda
本题考点: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>