老师看下是否正确,谢谢

来源:3-3 编程练习

闪电打雷躲树下

2022-08-14 14:47:21

<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.age=age;
         this.name=name;
         this.say(){
             console.log(this.name,this.age)
         }
     }
       run(){
         console.log('run')
     }
     static intro(){
         return 'this is a Person class'
     }
     static show(){
          console.log('show')
     }
 }
 
 
</script>


写回答

1回答

好帮手慕慕子

2022-08-14

同学你好,整体思路是对的,但是其中有个语法是错误的,通过this添加say方法时,不可以使用简写方式,建议修改:

https://img.mukewang.com/climg/62f89e680920b20311180484.jpg

另外,自己测试时,建议书写静态属性,示例:

https://img.mukewang.com/climg/62f89ead09f5d2eb10160564.jpg

祝学习愉快~

0

0 学习 · 17877 问题

查看课程