有一个疑问
相关代码:
<!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 = ()=> {
// console.log(this);
console.log(this.name,this.age);
}
}
run(){
console.log('run');
}
static intro = 'this is a Person class';
static show(){
console.log('show');
}
}
const p1 = new Person('xx',18);
console.log(p1.age,p1.name);
console.log(p1.say());
console.log(p1.run());
console.log(Person.intro);
console.log(Person.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('zs', 18);
// console.log(p.age);
// console.log(p.name);
// console.log(p.say());
// console.log(Person.intro);
// Person.show();
</script>
</body>
</html>相关截图:

问题描述:
为什么我每次调用一次方法都会多出一个undefined出来呢
问题描述:还有个代码显示的问题,出现好多次,之前反馈过这样的问题但是还是没有完全解决这个代码的显示问题,有时候是显示正常的,有时候显示不正常,前一个月的时候不会出现这样的问题的,希望老师反馈一下,因为有时候也会参考一下别人的代码或者复查自己代码也会重新找来看,但现在这个显示方式实在头疼

19
收起
正在回答 回答被采纳积分+1
1回答




恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星