请老师检查代码

来源:3-3 编程练习

xcn_aaaa

2022-10-24 20:48:19

<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>

<body>
<script>
/*
    function Person(name, age) {
        this.name = name;
        this.age = age;
        this.say = function() {
             console.log(this.name, this.age)
        }
    }
    Person.prototype.run = function() {
        console.log("run")
    }
    Person.intro = "this is a Person class"
    Person.show = function() {
        console.log('show')
    }
*/
    class Person {
        constructor(name,age){
            this.name = name;
            this.age = age;
            this.say = function(){
                console.log(this.name,this.age);
            }
        }
        run(){
            console.log('run');
        }
        static show(){
            console.log('show');
        }
        static getIntro(){
            return 'this is a Person class'
        }
    }
</script>
</body>

</html>


写回答

1回答

好帮手慕星星

2022-10-25

同学你好,代码是可以的。

建议:自己练习可以写静态属性,不改为方法

https://img.mukewang.com/climg/63573f2d0931b2f806670139.jpg

祝学习愉快!

0

0 学习 · 17877 问题

查看课程