javascript - 一个 var 怎么能有一个值,然后在同一个 console.log 消息中被取消分配?
问题描述
我可能遗漏了一些明显的东西,我有一个分配给this.theValue
. 立即记录此值表明它this.theValue
具有价值。后来这个值神奇地未定义。但是,如果我记录以下内容console.log(this, this.theValue)
,则第一个显示 theValue 存在,但 this.theValue 未定义。
这是它的样子:
/*global define, window */
define([
'competitor/show/CompetitorLabelColours',
'competitor/show/CompetitorLabelText'
], function(
CompetitorLabelColours,
CompetitorLabelText
) {
'use strict';
let CompetitorLabelFactory = function(parameterSet) {
this.parameterSet = parameterSet;
this.labeltext = new CompetitorLabelText(parameterSet);
this.labelColours = new CompetitorLabelColours(parameterSet);
console.log(this, this.labelText); //here none of them is undefined
this.scale = 0.5;
this.scaleLabel = 0.5;
this.opacity = 0.8;
};
...
CompetitorLabelFactory.prototype.update = function (competitor, entity) {
return {
...
labelTextRefresh: () => {
console.log(this, this.labelText); // here this.labelText is undefined
entity.label.text = this.labelText.updateText(competitor);
}
...
}
};
...
return CompetitorLabelFactory;
});
有什么我想念的想法吗?
我已经搜索了我的整个项目,并且这个变量永远不会重新分配。
解决方案
我在 的定义中看到了大小写差异labelText
,您为 分配了一个值labeltext
,所以undefined
当您记录它时
推荐阅读
- java - 用另一个 Spark Java 替换一列值
- mql4 - MQL4 的 _Point 的 PineScript 等价物是什么?
- php - 如何用 ChromDriver 和 yii2 解决“元素不可交互”?
- c - 为什么我的开关盒不适用于乘法或加法
- vue.js - 如何应用选择器选项仅在 Element UI 日期选择器中启动日历
- material-ui - Material UI IconButton onClick 不允许处理事件
- javascript - 无法选择元素:找不到节点
- flutter - 从一个更改到另一个时,所有选项卡都会不断重建
- html - 如何让图像填充 div 内的剩余空间?
- java - 在泛型 Collection 方法中发送 ArrayList