summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAvi Halachmi (:avih) <avihpit@yahoo.com>2019-12-15 09:20:01 +0200
committerAvi Halachmi (:avih) <avihpit@yahoo.com>2019-12-19 16:23:19 +0200
commit3d2e30d764cdf5f89ce743b6f2f8c2f3f659b2ff (patch)
tree4a8a223755a75bed0507725c41b65085955b5590
parentc4ae7d82036e8533a52281819ac78a186827515b (diff)
downloadmpv-3d2e30d764cdf5f89ce743b6f2f8c2f3f659b2ff.tar.bz2
mpv-3d2e30d764cdf5f89ce743b6f2f8c2f3f659b2ff.tar.xz
DOCS: js: minor update for modules/require
-rw-r--r--DOCS/man/javascript.rst17
1 files changed, 10 insertions, 7 deletions
diff --git a/DOCS/man/javascript.rst b/DOCS/man/javascript.rst
index 8399c77d6a..0c29affcdf 100644
--- a/DOCS/man/javascript.rst
+++ b/DOCS/man/javascript.rst
@@ -278,9 +278,11 @@ CommonJS modules and ``require(id)``
------------------------------------
CommonJS Modules are a standard system where scripts can export common functions
-for use by other scripts. A module is a script which adds properties (functions,
-etc) to its invisible ``exports`` object, which another script can access by
-loading it with ``require(module-id)`` - which returns that ``exports`` object.
+for use by other scripts. Specifically, a module is a script which adds
+properties (functions, etc) to its pre-existing ``exports`` object, which
+another script can access with ``require(module-id)``. This runs the module and
+returns its ``exports`` object. Further calls to ``require`` for the same module
+will return its cached ``exports`` object without running the module again.
Modules and ``require`` are supported, standard compliant, and generally similar
to node.js. However, most node.js modules won't run due to missing modules such
@@ -293,10 +295,11 @@ will load the file ``./foo.js`` and return its ``exports`` object.
An id is relative (to the script which ``require``'d it) if it starts with
``./`` or ``../``. Otherwise, it's considered a "top-level id" (CommonJS term).
-Top level id is evaluated as absolute filesystem path if possible (e.g. ``/x/y``
-or ``~/x``). Otherwise, it's searched at ``scripts/modules.js/`` in mpv config
-dirs - in normal config search order. E.g. ``require("x")`` is searched as file
-``x.js`` at those dirs, and id ``foo/x`` is searched as file ``foo/x.js``.
+Top level id is evaluated as absolute filesystem path if possible, e.g. ``/x/y``
+or ``~/x``. Otherwise, it's considered a global module id and searched at
+``scripts/modules.js/`` in mpv config dirs - in normal config search order. E.g.
+``require("x")`` is searched as file ``x.js`` at those dirs, and id ``foo/x`` is
+searched as file ``x.js`` inside dir ``foo`` at those dirs.
No ``global`` variable, but a module's ``this`` at its top lexical scope is the
global object - also in strict mode. If you have a module which needs ``global``