What is the best way to store constant values in JavasciptMVC

1.4k views Asked by At

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
1

There are 1 answers

3
Bergi On

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, {…});.