我的节点代码中有以下代码片段。
var fs = require('fs');
fs.readdir(__dirname, function (err, files) {
console.log(files);
});
为什么变量'__dirname'有双下划线?
我知道一个下划线是私有/受保护变量的命名约定...但是双下划线是否还意味着更多?
__dirname
and __filename
对于每个模块来说都是本地的,但其特殊性是字符串。
http://nodejs.org/docs/latest/api/globals.html http://nodejs.org/docs/latest/api/globals.html
文档指定:
__dirname isn't actually a global but rather local to each module.
通常下划线表示私有(在Javascript中,这个下划线是什么意思? https://stackoverflow.com/questions/8288756/in-javascript-what-does-this-underscore-mean/8288762#8288762 )
它可以被解释为模块的本地私有变量。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)