请老师检查,谢谢

来源:3-3 编程练习

慕的地7233660

2022-06-13 11:54:04

class Person{
    constructor(name,age){
        this.name=name
        this.age=age
       // this.say=function(){
       //     console.log(this.name,this.age)
       // }
    }
    run(){
    console.log('run')
   }
    say(){
         console.log (this.age,this.name)
    }

    static intor(){
        return "this is a Person class" 
    }
    static show(){
        console.log('show')
    }
   }

   const zs=new Person('张三',18)
  
   zs.say()
   zs.run()
  console.log(Person.intor())
  Person.show()


写回答

1回答

好帮手慕慕子

2022-06-13

同学你好,say方法是添加到实例对象上的,建议书写在constructor里面,示例:

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

虽然目前静态属性还处于提案中,但是针对本练习题,intro是静态属性,建议调整下:

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

祝学习愉快~

0

0 学习 · 17877 问题

查看课程