简体   繁体   English

带有JavaScript中带有重音符号键的对象的奇怪行为

[英]Strange behavior with objects with keys containing accented characters in Javascript

For a project, I am running a NodeJS app using Express. 对于一个项目,我正在使用Express运行NodeJS应用程序。 I wanted to organize my code and put some objects in a module I am calling with a require. 我想组织代码并将一些对象放入需要调用的模块中。

Something like var xlsImport = require(path.join(__dirname, '../config/xlsImport.js'))(mongoose, mongooseAppUsers, mongooseNodeJS_Test); var xlsImport = require(path.join(__dirname, '../config/xlsImport.js'))(mongoose, mongooseAppUsers, mongooseNodeJS_Test);类的东西var xlsImport = require(path.join(__dirname, '../config/xlsImport.js'))(mongoose, mongooseAppUsers, mongooseNodeJS_Test);

My module looks like : 我的模块看起来像:

    module.exports = function (mongoose,mongooseAppUsers,mongooseNodeJS_Test) {
    var module={};
(...)
    module.convertField = {
(...)
        "Jeu":                     "game",
        "Démo":                    "demo",
(...)
    return module;
};

In the main file, 在主文件中

xlsImport.convertField['Jeu'] is "game"
xlsImport.convertField['Démo'] is undefined

In the module, both are OK ! 在模块中,都可以!

I suspect a copy mechanism to be involved... 我怀疑涉及复制机制...

Any suggestion for solving that problem ? 有解决这个问题的建议吗? (and some hints about the why ?) (以及有关为什么的一些提示?)

I got it ! 我知道了 !

It all comes form my editor... When I moved my code from the main file to another newly created, the file encoding was different (windows-1252 instead of UTF-8 -I don't know why-). 所有这些都来自我的编辑器...当我将代码从主文件移动到另一个新创建的文件时,文件编码是不同的(Windows-1252而不是UTF-8-我不知道为什么-)。 The accented characters were not the same depending on when they were written. 带有重音符号的字符取决于书写时间。

No strange javascript behavior... 没有奇怪的JavaScript行为...

I hope this could help somebody else in the future... 我希望这可以在将来对其他人有所帮助...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM