I have a set of jQuery plugins I’m creating for a website.
All of these plugin have the common functionality that they make $.getJSON() calls.
The URL passed in these calls varies based on Dev, QA and production environments.
I would like to store the URL in a central place so it can be easily changed.
Where should the URL be stored? I don’t want to store the URL in each individual plugin.
Can it be defined as a global variable or is it better to make it an argument passed to the plugin?
I would recommend you use an object literal attached to the jQuery object. Just be sure to include it before all your plugins:
Then anywhere you need it, just use
If you use objects/classes in combination with the
$.fnfunctions, you can also use this global variable as a namespace: