Javascript pass reference by value

Posted by Carlos R. Batista on Stack Overflow See other posts from Stack Overflow or by Carlos R. Batista
Published on 2012-10-03T03:32:35Z Indexed on 2012/10/03 3:37 UTC
Read the original article Hit count: 212

Filed under:
|
|

Im having this weird reference issue when im trying to get a JSON file through query:

    var themeData;
    $.getJSON("json/sample.js", function(data) {
                themeData = data.theme;
                        console.log(themeData.sample[0].description);
            }); 
   console.log(themeData.sample[0].description);

The first console.log works, the second doesnt. Im guessing because "data" already expired by the time the script gets there and themeData is just a mere pointer to "data". Is there a ways I can make sure themeData gets a duplicate of "data" and not just a pointer to it?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery