题解 | #Getter#

Getter

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

<!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>Document</title>
</head>

<body>

    <script>
        class Rectangle {
            // 补全代码

            constructor(height, width) {
                this.height = height;
                this.width = width;
            }
            get area() {
                return this.Calcarea();
            }
            Calcarea() {
                return this.height * this.width;
            }
        }

        console.log(new Rectangle(12, 12).area)

    </script>
</body>

</html>

全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务