这在 devtools 中是未定义的,即使这不是未定义的
this is undefined in devtools even if this is not undefined
"this" 在 devtool 控制台中未定义,但显然不是未定义。
一定是 devtools 中的错误?
当您检查 ES6/ES2015+ 代码(多亏了源映射)而不是 实际代码 时,它是可读性较差的 ES5 转译代码,this
属性 跟你在源码里看到的不一样
要访问 this
,请尝试在控制台中评估 _this
、_this1
、_this2
等以找到您正在寻找的上下文。
const loaded = () => {
this.setState({ loading: false });
};
// will be compiled/transpiled to
var _this = this;
var loaded = function loaded() {
_this.setState({ loading: false });
};
参考:https://www.sitepoint.com/bind-javascripts-this-keyword-react/
当您检查 ES6/ES2015+ 代码(多亏了源映射)而不是 实际代码 时,它是可读性较差的 ES5 转译代码,this
属性 跟你在源码里看到的不一样
要访问 this
,请尝试在控制台中评估 _this
、_this1
、_this2
等以找到您正在寻找的上下文。
const loaded = () => {
this.setState({ loading: false });
};
// will be compiled/transpiled to
var _this = this;
var loaded = function loaded() {
_this.setState({ loading: false });
};
参考:https://www.sitepoint.com/bind-javascripts-this-keyword-react/