对象中普通函数的this指向函数的调用者,下面是我在echarts使用过程出现的错误,我需要在function中拿到窗体this中的数据,但是未能成功
this.chart.setOption({
formatter: function (params) {
console.log(this) //undefined
}
}
对象中箭头函数的this指向当前窗体,并且不会改变,附上代码
this.chart.setOption({
formatter: (params) =>{
console.log(this)//当前窗体对象,以及对象的所有数据
}
}
这种方法在对象的方法中或者方法的方法中都可使用,