billy jean
billy jean

Reputation: 1419

Make js globally accessible to other dynamically loaded scripts

i am developing an MVC site which has many partials that are dynamically loaded. On my site i have a sort of taskbar which sits at the top of the site.

I would like to be able to access methods and properties from my 'taskbar' from any dynamically loaded script.. What is the best way to go about this?

I understand that it is in scope but is there some preferred way to do namespacing or what is the best practice for handling this kind of issue? thanks!

Upvotes: 0

Views: 40

Answers (1)

Lloyd
Lloyd

Reputation: 29668

You need to scope it to the window usually, sometimes this needs to be explicit, sometimes it doesn't, for example:

window.Taskbar = {};

These should be available to use anywhere in your scripts (assuming they're logically in the same window).

Upvotes: 1

Related Questions