题解 | #Getter#

Getter

https://www.nowcoder.com/practice/e7f3a2f429d945e49f5b48ef1065beda

本题考点:class、Getter取值函数

核心步骤:

  1. 创建Rectangle类,在默认方法constructor中写入width,heigh参数(当new Rectangle执行)
  2. 创建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>

全部评论

相关推荐

点赞 评论 收藏
分享
评论
1
1
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务