请老师检查代码
来源: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回答
同学你好,代码是可以的。
建议:自己练习可以写静态属性,不改为方法

祝学习愉快!