gpt4 book ai didi

javascript - var 怎么能有一个值,然后在同一个 console.log 消息中被取消分配?

转载 作者:行者123 更新时间:2023-11-29 20:48:13 25 4
gpt4 key购买 nike

我可能遗漏了一些明显的东西,我有一个分配给 this.theValue 的值。立即记录此值表明 this.theValue 具有值。后来这个值神奇地未定义。但是,如果我记录以下 console.log(this, this.theValue) 那么第一个显示 theValue 存在,但是 this.theValue 是未定义的。

enter image description here

这是它的样子:

/*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

关于javascript - var 怎么能有一个值,然后在同一个 console.log 消息中被取消分配?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53371890/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com