Showing the changes to DOCS/man/javascript.rst (1 of 2 files). Show all
Unified · Split
| @@ -240,6 +240,9 @@ Note: ``read_file`` and ``write_file`` throw on errors, allow text content only. · 239 unmodified lines | |||
| 240 | anything from the filesystem), and returns it as a function. Very similar | 240 | anything from the filesystem), and returns it as a function. Very similar |
| 241 | to a ``Function`` constructor, but shows at stack traces as ``fname``. | 241 | to a ``Function`` constructor, but shows at stack traces as ``fname``. |
| 242 | 242 | ||
| 243 | ``mp.module_paths`` | ||
| 244 | Global modules search paths array for the ``require`` function (see below). | ||
| 245 | |||
| 243 | Timers (global) | 246 | Timers (global) |
| 244 | --------------- | 247 | --------------- |
| 245 | 248 | ||
| @@ -301,6 +304,11 @@ or ``~/x``. Otherwise, it's considered a global module id and searched at · 55 unmodified lines | |||
| 301 | ``require("x")`` is searched as file ``x.js`` at those dirs, and id ``foo/x`` is | 304 | ``require("x")`` is searched as file ``x.js`` at those dirs, and id ``foo/x`` is |
| 302 | searched as file ``x.js`` inside dir ``foo`` at those dirs. | 305 | searched as file ``x.js`` inside dir ``foo`` at those dirs. |
| 303 | 306 | ||
| 307 | Search paths for global module id's are at the array ``mp.module_paths``, which | ||
| 308 | is searched in order. Initially it contains one item: ``~~/scripts/modules.js`` | ||
| 309 | such that it behaves as described above. Modifying it will affect future | ||
| 310 | ``require`` calls with global module id's which are not already loaded/cached. | ||
| 311 | |||
| 304 | No ``global`` variable, but a module's ``this`` at its top lexical scope is the | 312 | No ``global`` variable, but a module's ``this`` at its top lexical scope is the |
| 305 | global object - also in strict mode. If you have a module which needs ``global`` | 313 | global object - also in strict mode. If you have a module which needs ``global`` |
| 306 | as the global object, you could do ``this.global = this;`` before ``require``. | 314 | as the global object, you could do ``this.global = this;`` before ``require``. |