Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我知道 JavaScript 中没有常量,但是我想单独存储配置值以使它们易于查找和调整。
$.Class
我会选择#2。我猜 JSON 比扩展具有静态属性的类更具可读性。
但是,我不会使用 XHR 读取 JSON,而只是将其设计为 JSONP。然后 JSON 实际上得到一个对象字面量,它可以分配给应用程序的任何静态变量。你甚至可以通过使用像$.extend(MyClass, {…});.
$.extend(MyClass, {…});