天天看点

#yyds干货盘点# 前端歌谣的刷题之路-第九十八题-getter

前言

我是歌谣 我有个兄弟 巅峰的时候排名c站总榜19 叫前端小歌谣 曾经我花了三年的时间创作了他 现在我要用五年的时间超越他 今天又是接近兄弟的一天人生难免坎坷 大不了从头再来 歌谣的意志是永恒的 放弃很容易 但是坚持一定很酷 本题目源自于牛客网 微信公众号前端小歌谣

题目

请补全JavaScript代码,完成名为"Rectangle"的矩形类。要求如下:

1. 构造函数只包含两个参数,依次为"height"、"width"

2. 设置Getter,当获取该对象的"area"属性时,返回该对象"height"与"width"属性的乘积

#yyds干货盘点# 前端歌谣的刷题之路-第九十八题-getter
#yyds干货盘点# 前端歌谣的刷题之路-第九十八题-getter

​编辑

 核心代码

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>getter</title>
</head>
<body>
  <script type="text/javascript">class Rectangle {
        // 补全代码
         constructor(height,width){
            this.height = height;
            this.width = width;
            this.area</script>
</body>
</html>      
#yyds干货盘点# 前端歌谣的刷题之路-第九十八题-getter

总结

继续阅读