I am working on an open source javascript project using backbone that uses a bunch of global settings. For local development, we’d like for each developer to be able to set their own settings, but we want this to exist in a separate file so we can exclude it from the repository using .gitignore.
I come from a Django background and the convention is to have a settings.py and local_settings.py where settings.py simply does something like:
try:
from local_settings import *
except:
pass
Is there an equivalent javascript convention for local settings?
Yes, simply create a global object (or local to your namespace if you have one) containing all the settings:
Since globals are really global in JavaScript and not module-specific like in python there is no need to import anything.
If you want to extend/overwrite your settings object, you can e.g. use jQuery’s
$.extend()method: