普通函数:
function show() {
console.log(this)
}
show()
// 打印结果:Window
在严格模式下:
'use strict'
function show() {
console.log(this)
}
show()
// 打印结果: undefined
如果实在react中出现 this指向为undefined ,解决方法是 把这个方法定义为箭头函数:
show: () => {
...
}
普通函数:
function show() {
console.log(this)
}
show()
// 打印结果:Window
在严格模式下:
'use strict'
function show() {
console.log(this)
}
show()
// 打印结果: undefined
如果实在react中出现 this指向为undefined ,解决方法是 把这个方法定义为箭头函数:
show: () => {
...
}