RingoJS javascript - 在控制台上获取用户输入
当使用Rhino或RingoJS时,可以在控制台REPL上使用print
来打印输出(alert
不可用)。
除了 prompt
之外,可以使用什么来读取控制台上的用户输入?
我可以在哪里找到有关这些约定的信息、Rhino 和/或 RingoJS 中可用的 API 或他们遵循的 CommonJS 指南吗?
When using Rhino or RingoJS, one can use print
on the console REPL to print output (alert
is not available).
What can be used to read user input on the console, instead of prompt
?
Is there somewhere I can find information on these conventions, what APIs are available in Rhino and/or RingoJS, or is there a CommonJS guide they are adhering to?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
简而言之,目前没有从标准输入流读取字节的标准(广泛支持)方法。使用Rhino,您可以简单地使用Java“System.in”输入流; RingoJS 显然实现了系统模块。
看起来 CommonJS 小组 仍在开发 “系统”规范草案,其中包括一个“stdin”对象,它应该是一个输入流,其行为就像在“r”模式下打开的文件一样;这样的对象还应该包含“
read()
” 方法。但请注意,这些都是草案规范,看起来很少有 JavaScript 环境提供实现。在实现系统和 IO 规范的环境中,您应该能够执行以下操作:The short answer is that currently there is no standard (widely supported) way of reading bytes from the standard input stream. With Rhino you could simply use the Java "System.in" input stream; RingoJS does apparently implement the System module.
It looks like the CommonJS group is still working on a draft of the "System" specification which includes a "stdin" object which should be an input stream and behave just like a file opened in "r" mode; such an object should also include a "
read()
" method. Note however that these are all draft specs and it looks like very few JavaScript environments provide implementations. In an environment which does implement the System and IO specs you should be able to do something like this: