最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Double underscore in front of a variable - Stack Overflow

programmeradmin6浏览0评论

I have the following code snippet in my node code.

var fs = require('fs');

fs.readdir(__dirname, function (err, files) {
    console.log(files);
});

Why does the variable '__dirname' have double underscores? I know that one underscore is a naming convention for a private/protected variable... but does double underscore mean something more?

I have the following code snippet in my node code.

var fs = require('fs');

fs.readdir(__dirname, function (err, files) {
    console.log(files);
});

Why does the variable '__dirname' have double underscores? I know that one underscore is a naming convention for a private/protected variable... but does double underscore mean something more?

Share Improve this question edited May 27, 2014 at 8:14 jgillich 76.6k7 gold badges60 silver badges88 bronze badges asked May 27, 2014 at 8:13 Anders ÖstmanAnders Östman 3,8326 gold badges29 silver badges50 bronze badges 2
  • 2 It's just a naming convention.. – user2864740 Commented May 27, 2014 at 8:15
  • 2 No, it has no other meaning than a naming convention. – Henrik Andersson Commented May 27, 2014 at 8:15
Add a ment  | 

1 Answer 1

Reset to default 5

__dirname and __filename are local to each module but with the particularity that are strings.

http://nodejs/docs/latest/api/globals.html

documentation specifies:

__dirname isn't actually a global but rather local to each module.

and normally underscore means private ( In Javascript, what does this underscore mean? )

It can be interpreted as a local private variable to the module.

发布评论

评论列表(0)

  1. 暂无评论