javascript - NodeJS 中的双下划线与单下划线

标签 javascript node.js naming-conventions

我在使用 NodeJS 时遇到了 2 个相互冲突的命名约定。有些变量以单下划线开头,例如 _temp,而有些变量以双下划线开头,例如 __dirname

我一直在尝试寻找这种命名约定差异的答案。我查看了Double Underscore in front of a variable但答案非常具体于 __dirname__filename。它没有解决冲突的命名约定。

如果有人能为我提供这方面的资源,那就太好了。

最佳答案

即使我是 Node.js 新手并正在寻找答案。在node.js文档中找到了答案。请参阅Node.js - Globals了解更多详情。

正如上面的答案,带有单下划线(_private)的变量是定义私有(private)变量。

双下划线 (__) 在 Node.js 中没有任何约定。 Node.js 中只有两个带有双下划线的变量(称为全局对象)。

__dirname : used when to get the name of the directory that the currently executing script resides in.

__filename : used to get the filename of the code being executed.

关于javascript - NodeJS 中的双下划线与单下划线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35946339/

相关文章:

android - Android SD卡存储有什么约定吗?

java - main() 方法的 Java 类的包约定

JavaScript 数字表示

javascript - javascript 中的 for(let key in object) 有什么问题? IDE 警告似乎多余

c# - 使用 Elmah 进行 ASP.NET 监控

javascript - 转换为小写字母并去除空格js

javascript - 为什么我不能在浏览器 : You may not have the required environment or OS to run this project 中运行空白的 Cordova 应用程序

javascript - 在 js 中存储对 this 的引用的约定

javascript - 可视化分层数据

php - Onchange 事件与 jquery slider 一起使用