I need to access from several js files a global constant SETTINGS that is defined in a different js file. Researching the matter, I’ve come across all of the following alternatives:
window.SETTINGSwindow.parent.SETTINGSwindow.top.SETTINGS
What’s the difference, if any, between these alternatives? Is any one of them considered “best practice”?
When the current context is the top frame, then
window,topandparentare identical.Otherwise,
windowrefers to the current context,parentto the parent andtopto the top frame.External scripts run in the same context as the document where they’re embedded. So, use
window.SETTINGS.