how can a var have a value and then be unassigned in the same console.log message?
up vote
2
down vote
favorite
I'm probably missing something obvious, I have a value which is assigned to this.theValue
. Logging this value straight away shows that this.theValue
has a value. Later on this value is magically undefined. If I however log the following console.log(this, this.theValue)
then the first one shows that theValue exists, but this.theValue is undefined.
This is what it looks like:
/*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;
});
Any ideas what I'm missing?
I have searched my entire project and this variable is never reassigned.
javascript
add a comment |
up vote
2
down vote
favorite
I'm probably missing something obvious, I have a value which is assigned to this.theValue
. Logging this value straight away shows that this.theValue
has a value. Later on this value is magically undefined. If I however log the following console.log(this, this.theValue)
then the first one shows that theValue exists, but this.theValue is undefined.
This is what it looks like:
/*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;
});
Any ideas what I'm missing?
I have searched my entire project and this variable is never reassigned.
javascript
1
@Bergi its not really a duplicate and in the end the problem was something totally different. So please unmark it as a duplicate.
– just_user
5 hours ago
add a comment |
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I'm probably missing something obvious, I have a value which is assigned to this.theValue
. Logging this value straight away shows that this.theValue
has a value. Later on this value is magically undefined. If I however log the following console.log(this, this.theValue)
then the first one shows that theValue exists, but this.theValue is undefined.
This is what it looks like:
/*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;
});
Any ideas what I'm missing?
I have searched my entire project and this variable is never reassigned.
javascript
I'm probably missing something obvious, I have a value which is assigned to this.theValue
. Logging this value straight away shows that this.theValue
has a value. Later on this value is magically undefined. If I however log the following console.log(this, this.theValue)
then the first one shows that theValue exists, but this.theValue is undefined.
This is what it looks like:
/*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;
});
Any ideas what I'm missing?
I have searched my entire project and this variable is never reassigned.
javascript
javascript
asked 11 hours ago
just_user
4,94095995
4,94095995
1
@Bergi its not really a duplicate and in the end the problem was something totally different. So please unmark it as a duplicate.
– just_user
5 hours ago
add a comment |
1
@Bergi its not really a duplicate and in the end the problem was something totally different. So please unmark it as a duplicate.
– just_user
5 hours ago
1
1
@Bergi its not really a duplicate and in the end the problem was something totally different. So please unmark it as a duplicate.
– just_user
5 hours ago
@Bergi its not really a duplicate and in the end the problem was something totally different. So please unmark it as a duplicate.
– just_user
5 hours ago
add a comment |
1 Answer
1
active
oldest
votes
up vote
2
down vote
accepted
I see a case difference in the definition of labelText
, you assign a value to labeltext
, so it is undefined
when you log it
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
I see a case difference in the definition of labelText
, you assign a value to labeltext
, so it is undefined
when you log it
add a comment |
up vote
2
down vote
accepted
I see a case difference in the definition of labelText
, you assign a value to labeltext
, so it is undefined
when you log it
add a comment |
up vote
2
down vote
accepted
up vote
2
down vote
accepted
I see a case difference in the definition of labelText
, you assign a value to labeltext
, so it is undefined
when you log it
I see a case difference in the definition of labelText
, you assign a value to labeltext
, so it is undefined
when you log it
answered 11 hours ago
axelduch
9,17622044
9,17622044
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53371890%2fhow-can-a-var-have-a-value-and-then-be-unassigned-in-the-same-console-log-messag%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
@Bergi its not really a duplicate and in the end the problem was something totally different. So please unmark it as a duplicate.
– just_user
5 hours ago