简体   繁体   English

在 console.log 中显示错误的类名

[英]Wrong Class Name Showing in console.log

In Node.js, I've created a class in which I'm logging instances of that class to the console during tests.在 Node.js 中,我创建了一个类,在该类中我在测试期间将该类的实例记录到控制台。

When I console.log(anObjectFromThatClass), the letters "Vo" precede the opening curly brackets of that object in the terminal's output.当我 console.log(anObjectFromThatClass) 时,字母“Vo”在终端输出中该对象的左大括号之前。

Normally, I'd expect to see the class name preceding the curly brackets, but instead I see Vo {} .通常,我希望看到大括号前面的类名,但我看到的是Vo {} The actually class name does not have a "V" or an "o" anywhere in its name, nor does it extend another class having a "V" or "o" in its name.实际的类名在其名称中的任何位置都没有“V”或“o”,也不会扩展名称中带有“V”或“o”的另一个类。

I tried googling to see what "Vo" means, but couldn't find anything due to all the false positives of that search.我试着用谷歌搜索看看“Vo”是什么意思,但由于该搜索的所有误报,找不到任何东西。

Due to policy, I can't post the actual class here.由于政策原因,我无法在此处发布实际课程。 I realize I'm not giving you much to go on, but can you think of a reason why "Vo" would precede the curly brackets when console logging an instance of a class not containing 'Vo' in its name?我意识到我没有给你太多内容,但是你能想出为什么在控制台记录一个名称中不包含“Vo”的类的实例时“Vo”会放在大括号之前的原因吗? Does it have something to do with some type of live view provided by the V8 engine to node.js?它与 V8 引擎提供给 node.js 的某种类型的实时视图有关吗?

I've tried to create a class that reproduces this behavior, for this post, but every class I create, simply logs the correct class name before the curly brackets.对于这篇文章,我尝试创建一个重现这种行为的类,但是我创建的每个类都只是在大括号之前记录正确的类名。 This code has a lot of promises and async await stuff going on, perhaps that can alter class-names outputted by console.log?这段代码有很多承诺和异步等待的东西,也许这可以改变由 console.log 输出的类名?

I should probably just be glad this code is working good and forget about the idiosyncrasies of console.log() .我应该很高兴这段代码运行良好,而忘记了console.log()的特性。 However, I remain very curious, so please tell me if you know what this 'Vo' means.但是,我仍然很好奇,所以如果你知道这个“Vo”是什么意思,请告诉我。

The letters that come before the logged object when it gets console.log ged will be the name of the class, as it's represented in the code that was run .日志对象获得console.log ged 时出现在记录对象之前的字母是类的名称,因为它在运行的代码中表示 It sounds like the code that gets run is different from your source code - perhaps it's minified in some way, resulting in the run code having a class Vo { or something of the sort, even if the source code uses class MyClass { .听起来运行的代码与您的源代码不同 - 也许它以某种方式被缩小,导致运行代码具有class Vo {或类似的东西,即使源代码使用class MyClass {

If the code is run without minification or other transpilation, you'll see MyClass { instead of Vo { when the object gets logged.如果代码在没有缩小或其他转换的情况下运行,当对象被记录时,您将看到MyClass {而不是Vo {

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

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