我试图使用REPL来获取属于node.js中某个模块的函数的一些文档手册页面。
Console.dir(modObj)列出了属于模块的所有方法和属性。此外,我无法找到任何手册或针对该功能的帮助,这些手册或手册无法演示该功能的示例和用法。
这在Python Interactive Shell中非常简单,如下所示。浏览模块的官方在线文档是一种替代方法。 REPL是否对所有模块的手册页都具有内置支持?
在Python Interactive Shell中:-
import os
dir (os)
['EX_CANTCREAT', 'EX_CONFIG', 'EX_DATAERR', 'EX_IOERR', 'EX_NOHOST', 'EX_NOINPUT', 'EX_NOPERM', 'EX_NOUSER', 'EX_OK', 'EX_OSERR', 'EX_OSFILE', 'EX_PROTOCOL', 'urandom', 'utime', 'wait', 'wait3', 'wait4', 'waitpid', 'walk', 'write']
help(os.walk)
Help on function walk in module os:
walk(top, topdown=True, onerror=None, followlinks=False)
Directory tree generator.
For each directory in the directory tree rooted at top (including top
itself, but excluding '.' and '..'), yields a 3-tuple
dirpath, dirnames, filenames
dirpath is a string, the path to the directory. dirnames is a list of
the names of the subdirectories in dirpath (excluding '.' and '..').
filenames is a list of the names of the non-directory files in dirpath.
Note that the names in the lists are just names, with no path components.
To get a full path (which begins with top) to a file or directory in
dirpath, do os.path.join(dirpath,name).
在节点的REPL中:-
> var fs=require('fs')
undefined
> console.dir(fs)
{ Stats: [Function],
F_OK: 0,
R_OK: 4,
W_OK: 2,
X_OK: 1,
access: [Function],
accessSync: [Function],
exists: [Function],
existsSync: [Function],
readFile: [Function],
readFileSync: [Function],
close: [Function],
closeSync: [Function],
open: [Function],
openSync: [Function],
read: [Function],
readSync: [Function],
write: [Function],
writeSync: [Function],
rename: [Function],
renameSync: [Function],
truncate: [Function],
truncateSync: [Function],
ftruncate: [Function],
ftruncateSync: [Function],
rmdir: [Function],
rmdirSync: [Function],
fdatasync: [Function],
fdatasyncSync: [Function],
fsync: [Function],
fsyncSync: [Function],
mkdir: [Function],
mkdirSync: [Function],
readdir: [Function],
readdirSync: [Function],
fstat: [Function],
lstat: [Function],
stat: [Function],
fstatSync: [Function],
lstatSync: [Function],
statSync: [Function],
readlink: [Function],
readlinkSync: [Function],
symlink: [Function],
symlinkSync: [Function],
link: [Function],
linkSync: [Function],
unlink: [Function],
unlinkSync: [Function],
fchmod: [Function],
fchmodSync: [Function],
chmod: [Function],
chmodSync: [Function],
fchown: [Function],
fchownSync: [Function],
chown: [Function],
chownSync: [Function],
_toUnixTimestamp: [Function: toUnixTimestamp],
utimes: [Function],
utimesSync: [Function],
futimes: [Function],
futimesSync: [Function],
writeFile: [Function],
writeFileSync: [Function],
appendFile: [Function],
appendFileSync: [Function],
watch: [Function],
watchFile: [Function],
unwatchFile: [Function],
realpathSync: [Function: realpathSync],
realpath: [Function: realpath],
createReadStream: [Function],
ReadStream:
{ [Function: ReadStream]
super_:
{ [Function: Readable]
ReadableState: [Function: ReadableState],
super_: [Object],
_fromList: [Function: fromList] } },
FileReadStream:
{ [Function: ReadStream]
super_:
{ [Function: Readable]
ReadableState: [Function: ReadableState],
super_: [Object],
_fromList: [Function: fromList] } },
createWriteStream: [Function],
WriteStream:
{ [Function: WriteStream]
super_: { [Function: Writable] WritableState: [Function: WritableState], super_: [Object] } },
FileWriteStream:
{ [Function: WriteStream]
super_: { [Function: Writable] WritableState: [Function: WritableState], super_: [Object] } } }
undefined
>
> help(fs.stat)
ReferenceError: help is not defined
at repl:1:1
at REPLServer.defaultEval (repl.js:252:27)
at bound (domain.js:287:14)
at REPLServer.runBound [as eval] (domain.js:300:12)
at REPLServer.<anonymous> (repl.js:417:12)
at emitOne (events.js:82:20)
at REPLServer.emit (events.js:169:7)
at REPLServer.Interface._onLine (readline.js:210:10)
at REPLServer.Interface._line (readline.js:549:8)
at REPLServer.Interface._ttyWrite (readline.js:826:14)