doc: clarify relation between a file and a module#9026
doc: clarify relation between a file and a module#9026marzelin wants to merge 2 commits intonodejs:masterfrom marzelin:patch-1
Conversation
I've found this sentence: `In Node.js, files and modules are in one-to-one correspondence.` a bit vague, so I propose replacing it with a more informative one.
|
Please wrap lines at 80 characters. |
doc/api/modules.md
Outdated
|
|
||
| Node.js has a simple module loading system. In Node.js, files and modules are | ||
| in one-to-one correspondence. As an example, `foo.js` loads the module | ||
| Node.js has a simple module loading system. In Node.js each JavaScript file is a separate module which means that all variables, constants, functions, etc. declared in the file can be accessed only in that specific file unless explicitly exposed using `exports`-`require` interface. As an example, `foo.js` loads the module |
There was a problem hiding this comment.
Node supports more than just JavaScript source files.
There was a problem hiding this comment.
You mean json, c++ addons? Are they treated as modules, too?
There was a problem hiding this comment.
You mean
json, c++ addons? Are they treated as modules, too?
Yes. :)
doc/api/modules.md
Outdated
|
|
||
| Node.js has a simple module loading system. In Node.js, files and modules are | ||
| in one-to-one correspondence. As an example, `foo.js` loads the module | ||
| Node.js has a simple module loading system. In Node.js each JavaScript file is a separate module which means that all variables, constants, functions, etc. declared in the file can be accessed only in that specific file unless explicitly exposed using `exports`-`require` interface. As an example, `foo.js` loads the module |
There was a problem hiding this comment.
Things can also be exposed outside of a module if they are declared as globals, for example.
There was a problem hiding this comment.
You mean adding something to global object? global is there but it should be the last resort or never used at all.
There was a problem hiding this comment.
I was referring to accidentally creating global variables, but yes, you could do that too. Definitely not something that we want to recommend, but still technically possible.
There was a problem hiding this comment.
omg Node doesn't use strict mode by default. That changes things a little bit. Current module system doesn't protect from polluting global namespace, but just reads and executes specified files. I hope Node.js will soon support ES2015 modules. Thanks for pointing this out.
|
TBH, I find the existing text to be more clear than the proposed changes. |
|
@cjihrig You know all Node ins and outs, so your point of view is different from somebody who just start out with this runtime. Is it too simplistic for you? (of course after sorting out mistakes you pointed out). |
Added short clarification
|
I've changed the text as suggested in the comments. What do you think about it now? |
|
Updated text LGTM (I think you've answered @cjihrig's comments) |
c133999 to
83c7a88
Compare
PR-URL: #9026 Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
|
Landed in f45eb16 |
PR-URL: #9026 Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
PR-URL: #9026 Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
PR-URL: #9026 Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
PR-URL: #9026 Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Checklist
Affected core subsystem(s)
doc
Description of change
I've found this sentence:
In Node.js, files and modules are in one-to-one correspondence.a bit vague, so I propose replacing it with a more informative one.