1

I know there are no constants in JavaScript however I would like to separately store configuration values to make them easy to find and tweak.

  1. Create a separate $.Class and store the key-value pairs in the static part
  2. Or have them read from a JSON configuration file
  3. Or something better
ene.andrei
  • 187
  • 1
  • 2
  • 9
  • 1
    One person's "best" is likely another's "worst". Go with something that works well for you, something that makes your work easier instead of harder. – Pointy Aug 04 '12 at 12:12

1 Answers1

1

I would go with option #2. I guess JSON is more readable than extending a class with static properties.

However, I would not read the JSON in with a XHR, but just design it as JSONP. The JSON then practically gets an object literal, which can be assigned to any static variable of your application. You even could build static class properties from it by using a padding function like $.extend(MyClass, {…});.

Bergi
  • 630,263
  • 148
  • 957
  • 1,375
  • I do make web service calls using JSONP, however I can't do that if I do not know the service URL for instance. The role of this configuration file is to store project wide settings that only change on deployment. I guess I should have mentioned this in the question. – ene.andrei Aug 04 '12 at 14:23
  • Yes, I know what you want to do. But you do know the url of the config file/script, don't you? – Bergi Aug 04 '12 at 14:29
  • Relative path more precisely, not URL. – ene.andrei Aug 04 '12 at 14:30