问题描述
我是JS新手,正在学习Eloquent JS。我已经知道,匿名函数(如我编写的重写toString属性的匿名函数)会立即执行。但是我不明白的是为什么它以后又返回undefined。
class Rabbit{
constructor(type){
this.type = type;
}
speak(line){
console.log("hello");
}
}
let killerRAbbit = new Rabbit("killer");
Rabbit.prototype.toString = function() {
return `${this.type},${this.speak()}`;
};
console.log(killerRAbbit.toString());
我已经在firefox浏览器中执行了这段代码,得到的结果是
hello
killer,undefined
可以请别人解释一下吗?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)