报错是何原因?
javascript吧
全部回复
仅看楼主
level 1
maddylin 楼主
我下面这段JS程序为什么会报错,请高人指点,报错提示如下:
demo.html:35 Uncaught TypeError: p.say is not a function
at demo.html:35
<script>
class Person{
constructor(myName, myAge){
this.name = myName;
this.age = myAge;
this.hi = function () {
console.log("hi");
}
}
run(){
console.log("run");
}
}
let obj = {
constructor: Person,
type: "人",
say: function() {
console.log(this.name, this.age);
}
};
Person.prototype = obj;
let p = new Person("lnj", 34);
p.say();
console.log(p.type);
console.log(p);
</script>
2019年11月26日 07点11分 1
level 1
神仙写法。。。用了class还用原型。
2019年11月26日 11点11分 3
level 1
你看看es6里面class的标准吧,在类中声明方法的时候,千万不要给该方法加上function关键字
2019年11月30日 16点11分 4
1