Javascript中如何处理多种配置?
我有一个由 JScript/html 页面组成的应用程序,我想根据各种选项使它们可配置。 例如,这些选项之一是当前语言,它可能会修改页面的布局(我正在处理语言变化)(我正在开发 ERP,根据国家/地区可能适用不同的规则)。
我是这种技术的新手,我所考虑的是 Linux 内核中处理配置选项的方式。基本上,我会定义根据当前语言以不同方式扩展的宏(cpp 宏)。这样做时,交付的包仅包含一个国家/地区的页面,而我的代码库集中了所有内容。我不知道这是否是正确的方法,如果有的话。
希望这足够清楚..
I've an application made of JScript/html pages and I would like to make them configurable according to various options.
For instance, one of these options is the current language which may modify the layout (I'm dealing with language variation) of the page (i'm working on an ERP and according to the country different rules may apply).
I'm a newbie in this kind of technology and what I was thinking about is something like the way configuration options are dealt with in the linux kernel. Basically, I would define macros (cpp macros) which are expanded differently according to the current language. Doing so, the package delivered only contains the pages for one country while my codebase centralizes everything. I don't know if this is the right way to do it, if there's any.
hope this is clear enough..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这个问题相当笼统,所以很难给出一个好的答案。 js 中没有宏(除非你使用一些预处理器)。但 js 的动态特性可以让你动态地重新定义变量、函数等。您也许可以为每个国家/地区创建一个文件,然后将其包含在内,让它填补代码中的漏洞?
The question is fairly generic so it's hard to give a good answer. There are no macros in js (unless you use some preprocessor). But the dynamic nature of js lets you redefine variables, functions, etc on the fly. You could perhaps have a file for each country and just include that, letting it plug in the holes in your code?