Reputation: 35321
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.SETTINGS
window.parent.SETTINGS
window.top.SETTINGS
What's the difference, if any, between these alternatives? Is any one of them considered "best practice"?
Upvotes: 0
Views: 71
Reputation: 349042
When the current context is the top frame, then window
, top
and parent
are identical.
Otherwise, window
refers to the current context, parent
to the parent and top
to the top frame.
External scripts run in the same context as the document where they're embedded. So, use window.SETTINGS
.
Upvotes: 1