RingoJS javascript - 在控制台上获取用户输入

发布于 2024-12-29 05:48:42 字数 213 浏览 8 评论 0原文

当使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

清音悠歌 2025-01-05 05:48:42

简而言之,目前没有从标准输入流读取字节的标准(广泛支持)方法。使用Rhino,您可以简单地使用Java“System.in”输入流; RingoJS 显然实现了系统模块

看起来 CommonJS 小组 仍在开发 “系统”规范草案,其中包括一个“stdin”对象,它应该是一个输入流,其行为就像在“r”模式下打开的文件一样;这样的对象还应该包含“read()” 方法。但请注意,这些都是草案规范,看起来很少有 JavaScript 环境提供实现。在实现系统和 IO 规范的环境中,您应该能够执行以下操作:

var system = require('system');
system.stdin.read(10); // Read ten bytes.

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:

var system = require('system');
system.stdin.read(10); // Read ten bytes.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文