My understanding (Based on experience and posts like this) If my Javascript does this:
global_var = {'key' : 'value'} Then I should be able to do this:
console.log(window.global_var) Or
console.log(window['global_var']) I expect those things to actually log the object to my console {'key':'value'}. In fact both of the latter two statements print undefined
I know I can do this:
window.global_var = {'key' : 'value'} But that's not what I want (just humor me)
I've tried this from Javascript files loaded to the page. I've also tried from the Chrome Developer Console, both directly (repeating above), and also using "Store as Global Variable"
=console.log({'key':'value'}) VM1587:1 Object {key: "value"} undefined {I right-click on the Object logged above and choose "save as Global Variable"} temp1 Object {key: "value"} window.temp1 undefined I am using Chrome Version 47.0.2526.106 m
global_var = {'key' : 'value'};-->window.global_var; Works for me in Chrome 47.ourcompany={}, so we could at least populate that. We simply make sure Script X.js is loaded before Script Y.js. But to be safer still I am trying to do this, stackoverflow.com/a/11596399/1175496 and oddly it tells mewindow.global_varis undefined, even though I can reach justglobal_var