0

I've got stuck with this issue.

var myModule = (function(){

    var foo;

    foo = "bab"; 
    console.log(foo);

    foo = "bab" + "more";
    console.log(foo);


    function mth1(){
      foo = "mag";
      console.log(foo);
    }

    return{
      pubMethod1: mth1 
    };

})();

myModule.pubMethod1();

The problem is that instead of this output:

"bab"
"bab more"
"mag"

I get this output:

"bab"
"mag"
"mag"

More specifically, the "bab more" is for some reason overwritten by mth1() value.

Original code publishing is not available.

Your thoughts much appreciated.

Tadas V.
  • 775
  • 1
  • 11
  • 22
  • Your code is working correctly for me http://jsfiddle.net/kcwxse4f/ are you sure there's nothing else involved? – Eduardo Wada Dec 05 '15 at 14:59
  • [No, that doesn't happen](http://jsfiddle.net/8yd3amLh/1/). In the process of simplifying the example, you've removed the code causing the behavior. Most likely it's the famous "console.log logging an object but deferring evaluation of it until you expand the object later" issue. – T.J. Crowder Dec 05 '15 at 14:59
  • T.J. Crowder could you please write console.log logging issue as an answer since this was actually part of the problem. Thank you! – Tadas V. Dec 05 '15 at 15:17

1 Answers1

0

Part of the problem, apart the original code bug, was console.log issue.

More info about here at StackOverflow.

Community
  • 1
  • 1
Tadas V.
  • 775
  • 1
  • 11
  • 22