What is the best way to create a global object? If a variable is created in the object for which a loaded DOM is needed. If a DOM loaded is not needed, then you can

photoFunc = { obj_size: 'eclipse' } 

And if you need something like that?

  document.addEventListener('DOMContentLoaded', function(){ photoEl() }, false); function photoEl(){ return photoFunc = { obj_size: document.getElementById('eclipse') } } 
  • return to event handlers is certainly cool, but useless - Specter

1 answer 1

The global object is created like this: window.globalObject = {}

  • one
    Is that the only way? 1. var globalObject = "globalObject"; window.globalObject // globalObject 2. (function () {this.globalObject = "globalObject";} ()); window.globalObject // globalObject 3. ... - Specter
  • so i need to make it global after loading the DOM - Zow
  • @Zow, you surprise me several times already with the inability to solve even the most elementary task own - Specter