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.



enter image description here



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.










share|improve this question


















  • 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















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.



enter image description here



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.










share|improve this question


















  • 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













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.



enter image description here



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.










share|improve this question













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.



enter image description here



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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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














  • 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












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






share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    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

























    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






    share|improve this answer

























      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






      share|improve this answer























        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






        share|improve this answer












        I see a case difference in the definition of labelText, you assign a value to labeltext, so it is undefined when you log it







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 11 hours ago









        axelduch

        9,17622044




        9,17622044






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            'app-layout' is not a known element: how to share Component with different Modules

            android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

            WPF add header to Image with URL pettitions [duplicate]