this的指向为什么是undefined
不知道你在开发中是否遇到过this的指向为undefined的问题呢例如:class Doge {constructor (name,age){ this.name = name this.age = age }cry(){ //console.log(this)}const d = new Dog('旺财','8')const x = d.cry()x() //undefined 为什么打印为undefined 呢,首先明确的是类中所有定义的方法,在浏览器运行时候全
原创
2021-06-14 20:03:59 ·
1768 阅读 ·
0 评论