麻烦老师检查,谢谢老师❤

来源:3-3 编程练习

宣7595077

2022-11-11 08:38:15

<!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 intro = "this is a Person class";
        static show() {
          console.log("show");
        }
      }
      const p = new Person("LiSi", 20);
      console.log(p.name, p.age);
      p.say();
      p.run();
      console.log(Person.intro);
      Person.show();
    </script>
  </body>
</html>

写回答

1回答

好帮手慕星星

2022-11-11

同学你好,代码是正确的。继续加油,祝学习愉快!

0

0 学习 · 17877 问题

查看课程